The name of the calling class in the header file

I just stumbled upon C ++ code with a class name at the top of the header file, e.g.

class CFoo; class CBar { .... }; 

My question is: what is class CFoo for?

Thanks a lot!

+4
source share
3 answers

This is called a forward ad. This means that there is a class called CFoo, which will be defined later in the file (or another included). This is usually used for pointers in classes, for example:

 class CFoo; class CBar { public: CFoo* object; }; 

This is a hint for the C ++ compiler saying that it does not worry that the type name is used without a definition, although it has not yet found a complete definition for CFoo.

+12
source

He triggered an announcement ahead.

http://en.wikipedia.org/wiki/Forward_declaration

+1
source
 class CFoo; 

It is simply a declaration that the class exists; even if you have not seen the definition, you can still play with (CFoo *) or (CFoo &) - that is, pointers and links to CFoo.

+1
source

All Articles