Unknown error rewrite specifier problem

When writing a program with multi-file compilation, I encountered an error:

Error C3646 "name": Unknown rewrite specifier

So I went to a search engine to search for what my predecessors thought about this error

Based on the experience on the Internet, I have summarized the possible situations in which this error occurs:

1. Circular references between header files

For example: include bh in ah and create a class b object, then include ah in bh.

Solution: Check the header relationship of the project's header file to prevent circular reference of the header file.

2. The question of semicolon

Careless use of Chinese semicolon in the code of the header file (usually it may be on the previous line of the error code)

Solution: Check the symbol in the error header file

3. When using a class that contains another class, the definition order of the two classes is wrong

Sample code:

class A{
B b;
}

class B{
int i;
}

In this code, class A is used to define an object in class A, but at this time the definition of class B is after class A, which may produce an "unknown rewrite specifier" error.
Solution: Check the life order of the class, the life order of the included class should be before the class that contains it.

#include
#include

#include"student.h"

using namespace std; the
program is very simple, there are only two files, main.cpp and student.h, which is the macro definition part of main.cpp (Student.h has no macro definition, just start to define the class). But after this compilation, the compiler will student.h of error: error C3646 "name": Unknown rewrite specifier (below, there are many, are of this, not list them here)
several times at random after After trying, I found that if #inlcude "student.h" is placed under using namespace std ;, this program can run normally. The modified main.cpp macro definition part is as follows:

#include
#include

using namespace std;

#include "student.h"
so that there is no "unknown rewrite specifier" error. Although this time it is skewed, it also shows that I have insufficient understanding of using namespace.
So I checked some things about using namespace.

Wow
Published 206 original articles · praised 18 · 70,000 views

Guess you like

Origin blog.csdn.net/lvmengzou/article/details/105549501