定义类csocket继承了CSocket
然后定义全局变量csocket cslisten;但是编译时候报错:syntax error : missing ';' before identifier 'cslisten'我是在CAboutDlg中直接写的全局变量。我这种添加全局变量的方式有错吗?
如果没有,那又是什么原因导致的呢?

解决方案 »

  1.   

    不懂!
    // serverDlg.cpp : implementation file
    //#include "stdafx.h"
    #include "server.h"
    #include "serverDlg.h"#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif
    csocket cslisten;
    int csnum=0;
      

  2.   

    如果csocket类对应的文件分别是cs.h、cs.cpp,则:
    在cs.cpp的构造函数之前声明:
    csocket cslisten;
    在cs.h的类之后声明:
    extern csocket cslisten;
    在所有需要用到这个变量的地方,添加:
    #include "cs.h"
    即可
      

  3.   

    csocket 类的头文件呢?
    #include "stdafx.h"
    #include "server.h"
    #include "serverDlg.h"//这里是不是少了这个
    #include "csocket.h"
      

  4.   

    加了#include <Winsock2.h>
    #pragma comment(lib, "WS2_32")