The error is as follows:
Error c2079: 'xxx' uses undefined class '***'
For example, we first define a class B and then a Class A. A member of Class A is B, as shown below:
Class B
{
Int I;
};
Class
{
B val;
};
Of course;
However, if we need to put the definition of B at the end, we all know that we should declare B before, then:
Class B;
Class {
B val;
};
Class B {
Int I;
};
Right? It seems that there is no error. It is a bit like declaring and calling a function in advance;
In fact, compilation fails;
Because at this time: Class B has not yet been allocated space, and Val cannot be defined and allocated space (because the compiler needs to allocate space for its members when processing the class );
Another person came to the conclusion that class names cannot be used for advanced reference to define variable parameters of variables and functions. They can only be used to define references or pointers.
Then, replace Val with the pointer to B:
Class B;
Class {
B * val;
};
Class B {
Int I;
};
Bingo!
Another interesting question is:
Class B;
Class;
Class {
B val;
};
Class B {
A val;
};
In this case, the two sides of the mirror are placed in the same way ..
When the Val of A is processed, it is found to be B, so leave space for B,
In order to know how much space is reserved for B, let's look at B and find that the Val of B is,
Then you need to know how much space A should be given...
At this time, an error occurs: Error c2079: 'xxx' uses undefined class '***'.