Sometimes, because the class is too large, it needs to be defined later in the class;
For example:
Class Y {void f (X) ;}; class X {// some member data and functions };
// Error
Because c ++ requires that any variable must be declared before reference ., In the above definition, we can change the order of the two.
But if a loop is formed?
Class X {void f1 (Y)}; class Y {void f (X );};
// Error
This kind of rule cannot be declared by the compiler before it is called by simply changing the sequence.
So we can first declare in the above?
Class Y; class X {void f1 (Y) // error}; class Y {void f (X );};
However, in the above Code, the f1 (Y) parameter is variable Y, and the specific structure of the entire class Y must be known at this time. So it is not feasible.
So we can change the parameter Y in function f1 ()
Class Y; class X {void f1 (Y *)}; class Y {void f (X );};
// Right
Changing the preceding parameter class Y to its pointer is feasible because the compiler knows how to pass an address, which is fixed in size. You do not need to know what objects are passed, even if we do not know the size of the object type to be passed.
However, here the function f2 () can use Class X as the parameter, because Class X has been fully defined.