Two C ++ compilation errors and solutions -- does not name a type and field 'xx' has incomplete type
Compilation Error 1: XX does not name a type
Compilation Error 2: Field 'xx' has incomplete type
Compilation Error 1: XX does not name a type, which means "XX does not name a type".
For example, if two classes are defined as follows:
Class B {
Public:
B (){}
~ B (){}
PRIVATE:
A;
};
Class {
Public:
A (){}
~ A (){}
PRIVATE:
Int;
};
When compiled, an error is reported: "A does not name a type"
The error is reported on the red line.
Even if clase A and Class B are defined in two files, this error is also reported when the # class a header file is included in the file header defining B (this is caused by the sequential relationship between compilation and links ).
Solution:
Before class B's definition declaration, declare Class A as follows:
Class;
Class B {
Public:
B (){}
~ B (){}
PRIVATE:
A;
};
Class {
Public:
A (){}
~ A (){}
PRIVATE:
Int;
};
Compilation Error 2: Field 'xx' has incomplete type
In the same way as in the above example, the first error has disappeared through problem 1, but the second error will appear immediately! Or the same location.
This error means that the XX domain type in Class B is incomplete. Why? It is clearly defined after Class. In fact, the reason is the same as the previous one. Before class B was defined, we only declared Class A without specific definitions. So the solution to this error is as follows:
Use the pointer instead of the field in the Class B definition. After correctionCodeIs:
Class;
Class B {
Public:
B (){}
~ B (){}
PRIVATE:
A *;
};
Class {
Public:
A (){}
~ A (){}
PRIVATE:
Int;
};
In this way, this simple code can be compiled without errors.