在互相引用头文件后,这两个类是CMySocket,Ctalkdlg
出现了这两个错误
                            missing ';' beforeidentifier 'm_sListenSocket'
我在Ctalkdlg.cpp声明了 CMySocket m_sListenSocket
d:\ben\talk\talkdlg.h(57) : error C2501: 'CMySocket' : missing storage-class or type specifiers                            syntax error : identifier 'CTalkDlg'
d:\ben\talk\mysocket.h(24) : error C2143: syntax error : missing ';' before '*'

解决方案 »

  1.   

    可以:
    头文件这样写:
    对A.h
    #ifndef _A_H
    #define _A_H
    ....
    #endif _A_H
    b.h类似:
    包含时这样做:
    #ifndef _A_H
    #include"a.h"
    #endif
    #ifndef _B_H
    #include "b.h"
    #endif
      

  2.   

    互相引用不太可能吧。
    我的做法是在头文件中前向定义一下。然后使用指针,像这样
    classa.hclass b;
    class a
    {
       b* B;
    };
    在a的实现文件中
    include <classb.h>
    或者把这两个类放到同一个文件中吧,不过这样也需要前向引用一下。
      

  3.   

    当然不能相互调用
    如果两个类都需要使用另外一个类,使用提前声明,并使用类指针
    在cpp文件中可以包含另外一个类的头文件