I was watching the video of accessing member functions through pointers and there is this statement i cant understand
GetOwner()->GetName();
how can a method call a method
I was watching the video of accessing member functions through pointers and there is this statement i cant understand
GetOwner()->GetName();
how can a method call a method
The method GetOwner() returns a pointer to an object, and then GetName() is called on that object.
You can think of it as:
GetOwner()->GetName();
is the same as:
(GetOwner())->GetName();
which results in:
(A Pointer to the Owner)->GetName();
or
(3 + 5)->GetName();
(8)->GetName();
But I Have Used ->operator to access elements of a Structure Using a Pointer
Yes. The → operator is really two operators in one package.
(*ptr).YourMember
The * dereferences the object and then you access it using the . operator. So the function returns a pointer to MyObject. Then you dereference that pointer to get the object itself like so: (*MyObject). My Object has a member function that you call. (*MyObject).MemberFunction(). Using the function instead of the variable we get (*GetMyObject()).MemberFunction(). Replacing the * operator and the . operator with the → operator we get GetMyObject()->MemberFunction()