VS C++ compiles C2146 and C4430 errors

Remember the pits you encounter

If you encounter an error like this:

error C2146: syntax error : missing ‘;’ before identifier
error C4430: missing type specifier - int assumed.

A C2146 error followed by one or more C4430 errors, you can consider checking whether the header files include each other.

like

-----AFile A.h-------
#include"A.h"
---------------------

-----BFile B.h-------
#include"B.h"
---------------------

However, the code error above is not the content of this article, and the actual error in this article is generally like this

-----AFile A.h-------
#ifnfine __A__
#define __A__
#include"A.h"
#endif
---------------------

-----BFile B.h-------
#include"B.h"
---------------------

Then one of A and B calls or declares the members of the other party, so that problems will develop when the preprocessing is expanded.

Another situation is that the class lacks a forward declaration

Guess you like

Origin blog.csdn.net/ninesnow_c/article/details/119574621