Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: C++
Expertise: Intermediate
Apr 25, 2006

Class Members that Are Class Objects Must Be Objects of Previously Declared Classes

A class employ can not contain an object of another class employ, but it may contain a pointer or reference to an object of a class employ.

The reason for this is that a class' size is not known until the end of its declaration. Before this, its name can only be used where its size need not be known. For example, in the following code, it may appear as though the definition of the employ::e() uses the sizeof employ before the end of the declaration of employ. However, this is not the case, because definitions of inline fuctions are not type checked until after the complete class declaration has been seen:


Class employ
{
     employ();
     employ *ptr; //here the size of the employ need not to be known
     static employ d;  //a declaration not a definition;
     employ info();
     int e() {return sizeof(employ);}
};
Neelam Kalra
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap