devxlogo

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

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);}};
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist