FVector::Dist(PlayerPawn->GetActorLocation(), GetActorLocation());

I remember back in the Building Escape project, there was a lecture about permanent storage, and my understanding was that the access operator, “::” is used to access member functions on items (what’s the proper word here??) in permanent storage. The examples given were

LEFT TERM			ACCESSOR		EXAMPLES
	- Class 			::				UGrabber::Grab
	- Enum			::				EWordStatus::OK
	- Namespace 		::				std::cout

I’m wondering what FVector would count as (e.g. a Class)? I always thought it was a Type or Struct, but I could be totally mixed up with my terminology, can you help me clarify this?

:: is the scope resolution operator. It is used to access things within a class, enum, or namespace.

In each example you are accessing names within the scope of the class/enum/namespace. Without it you would be trying to access names within the global namespace which may or may not exist.

FVector is a struct (same as a class, only difference being default access level) and Dist is a “static member function”. It’s within the class’ scope but doesn’t need an instance of that class.

struct Foo
{
    static void StaticFunc();
    void NonStaticFoo();
};

int main()
{
    Foo foo;

    foo.NonStaticFoo(); // needs Foo instance to call this function.
    Foo::StaticFoo(); // doesn't need an instance to call this function.

    foo.StaticFoo(); // rather unusual but fine, foo isn't needed or used here.
}
1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms