Click here to Skip to main content
11,438,007 members (51,213 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ function Pointer
Hello everybody, I was just wondering what this line really meant:
if (!Engine::GetEngine() -> GetIsWaiting());
I don't understand the "->" where GetEngine() function is like "looking inside (member)" GetIsWaiting(), whereas GetIsWaiting() it is not a class or smiliar. GetIsWaiting IT IS NOT a member of GetEngine() !!!
What is this supposed to be interpeted like? Both the constructor and function (Clearly) belong to the "GetEngine" class.

Thanks.
Posted 6-Dec-12 1:06am
Edited 6-Dec-12 1:17am
v5

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

It's not "looking inside" GetEngine - what happens is a lot more simple:
GetEngine is a function which returns a value - that value is a pointer to a class instance (presumably a GetEngine class instance)
The -> "looks inside" the class instance and finds the GetIsWaiting method, then calls it.
  Permalink  
Comments
unscathed18 at 6-Dec-12 6:37am
   
Woudln't be easier just to get the "this" pointer from the instanced object? Bytheway, Why it has to be an static member? Otherwise, the compiler won't let me go.
OriginalGriff at 6-Dec-12 6:50am
   
You need a pointer to the instanced object in order to evaluate the "this" pointer - which is the pointer to the instanced object! :laugh:

It has to be static, because otherwise you would need an instance of a class in order to access the GetEngine function.
It looks like this is an implementation of what is called a Singleton Pattern - there is only ever one instance of the class, and it is always accessed via a method - you cannot create one by using "new". If you call Engine::GetEngine() several times, it will always give you the same instance - and that is the only way to get the Engine to do anything.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web03 | 2.8.150506.1 | Last Updated 6 Dec 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100