class - Understanding of the objects creation in c++ -


if have class name app , class name manager. want create inside manager class app class, i've seen 2 options didn't understand difference.

choice 1:

//..... class app;  //writing line outside declaration of func class manager{ //..    private:  app *a; //... } 

or choice 2:

class manager{ //..  private: app *a; //.. } 

the class app; outside class manager { ... } forward declaration. tells compiler, "app class. i'm not going tell looks like, trust me, is."

think of compiler only knowing particular file (which assuming .h file) when compiles. have said member class includes pointer "app". "what heck app?" compiler wants know. without forward declaration (or perhaps #include app.h or similar), doesn't know, , fail compile. saying @ top, class app;, knows app class. that's needs know allocate space pointer in member class.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -