我自己建立了一个类CLoginSocket,在这个类中要用到CFCDlg的方法,所以建立一个指针,而在CFCDlg也需要用到CLoginSocket的方法。当我在2个类用互相包含对方的头文件,,出现下面的错误:
Compiling...
FC.cpp
e:\temp\fc\loginsocket.h(42) : error C2143: syntax error : missing ';' before '*'
e:\temp\fc\loginsocket.h(42) : error C2501: 'CFCDlg' : missing storage-class or type specifiers
e:\temp\fc\loginsocket.h(42) : error C2501: 'm_cFCDlg' : missing storage-class or type specifiers
Generating Code...
Compiling...
FCDlg.cpp
e:\temp\fc\loginsocket.h(42) : error C2143: syntax error : missing ';' before '*'
e:\temp\fc\loginsocket.h(42) : error C2501: 'CFCDlg' : missing storage-class or type specifiers
e:\temp\fc\loginsocket.h(42) : error C2501: 'm_cFCDlg' : missing storage-class or type specifiers
Generating Code...
Compiling...
LoginSocket.cpp
e:\temp\fc\fcdlg.h(60) : error C2146: syntax error : missing ';' before identifier 'm_cLoginSocket'
e:\temp\fc\fcdlg.h(60) : error C2501: 'CLoginSocket' : missing storage-class or type specifiers
e:\temp\fc\fcdlg.h(60) : error C2501: 'm_cLoginSocket' : missing storage-class or type specifiers
Generating Code...
Error executing cl.exe.FC.exe - 9 error(s), 0 warning(s)请问怎么解决??我觉得是头文件重复包含了~~~
Compiling...
FC.cpp
e:\temp\fc\loginsocket.h(42) : error C2143: syntax error : missing ';' before '*'
e:\temp\fc\loginsocket.h(42) : error C2501: 'CFCDlg' : missing storage-class or type specifiers
e:\temp\fc\loginsocket.h(42) : error C2501: 'm_cFCDlg' : missing storage-class or type specifiers
Generating Code...
Compiling...
FCDlg.cpp
e:\temp\fc\loginsocket.h(42) : error C2143: syntax error : missing ';' before '*'
e:\temp\fc\loginsocket.h(42) : error C2501: 'CFCDlg' : missing storage-class or type specifiers
e:\temp\fc\loginsocket.h(42) : error C2501: 'm_cFCDlg' : missing storage-class or type specifiers
Generating Code...
Compiling...
LoginSocket.cpp
e:\temp\fc\fcdlg.h(60) : error C2146: syntax error : missing ';' before identifier 'm_cLoginSocket'
e:\temp\fc\fcdlg.h(60) : error C2501: 'CLoginSocket' : missing storage-class or type specifiers
e:\temp\fc\fcdlg.h(60) : error C2501: 'm_cLoginSocket' : missing storage-class or type specifiers
Generating Code...
Error executing cl.exe.FC.exe - 9 error(s), 0 warning(s)请问怎么解决??我觉得是头文件重复包含了~~~
不会是MFC的东西吧,我新手~
在两个头文件中做了交叉包含,由于“预编译头文件标识宏”的存在,会使得一个头文件总是在另一个的前面。
这样在前面的那个头文件中申明的另一个头文件中的类的对象,就没了出处。
因此,就会出现:missing storage-class or type解决方法:
1、在 LoginSocket.h 中,申明一个外部类型,此时,只能定义这个类型的指针了,如:
……
class CFCDlg;
……
class LoginSocket
{
……
CFCDlg * m_pdlgFC;
……
};
2、再在LoginSocket.cpp 文件中包含 FCDlg.h。