第一次做CSocket的继承,碰到了个奇怪的问题。在同一个.CPP里不用继承写CSocket已经学会
不知道是没有做哪一步还是做错了哪一步,忘高手解答下小弟
具体操作如下:
1:新建工程。取名SocketTest对话框模式。勾选了windows sockets选项
2:新建类,选择MFC Class类型,取名MySocket 继续自 CSocket
3:在MySocket中重写构造方法。MySocket(CSocketTestDlg* m_pStd);并添加CSocketTestDlg* m_Std变量
   在构造方法的实现里将m_Std=m_pStd;

以上这些步骤编译时还没报错
接下来:
4:在CSocketTestDlg中添加MySocket* m_Msocket变量,并在构造函数的实现中将m_Msocket=NULL;只要这一步一做再编译就报错。
2边的头文件都已经include
有别人做的类似的项目我看过代码和我的一样。为什么我就编译报错了呢
一开始我以为是VC++6.0抽住了,clean了好几次都是会编译报错,而与我类似的项目却编译通过
所以我猜想是我以上做的步骤中缺少个哪一个重要步骤没有做。求高手解答解困

解决方案 »

  1.   

    CSocket不算是网络编程吗?
    头文件已经2边都包含了
    错误信息如下:
    Compiling...
    MySocket.cpp
    c:\test\sockertest\mysocket.h(23) : error C2629: unexpected 'class MySocket ('
    c:\test\sockertest\mysocket.h(23) : error C2238: unexpected token(s) preceding ';'
    c:\test\sockertest\mysocket.h(24) : error C2143: syntax error : missing ';' before '*'
    c:\test\sockertest\mysocket.h(24) : error C2501: 'CSockertestDlg' : missing storage-class or type specifiers
    c:\test\sockertest\mysocket.h(24) : error C2501: 'std' : missing storage-class or type specifiers
    c:\test\sockertest\aa.h(22) : error C2629: unexpected 'class aa ('
    c:\test\sockertest\aa.h(22) : error C2238: unexpected token(s) preceding ';'
    c:\test\sockertest\aa.h(27) : error C2143: syntax error : missing ';' before '*'
    c:\test\sockertest\aa.h(27) : error C2501: 'CSockertestDlg' : missing storage-class or type specifiers
    c:\test\sockertest\aa.h(27) : error C2501: 'm_socket' : missing storage-class or type specifiers
    C:\test\sockertest\MySocket.cpp(19) : error C2511: 'MySocket::MySocket' : overloaded member function 'void (class CSockertestDlg *)' not found in 'MySocket'
            c:\test\sockertest\mysocket.h(15) : see declaration of 'MySocket'
    sockertest.cpp
    c:\test\sockertest\aa.h(22) : error C2629: unexpected 'class aa ('
    c:\test\sockertest\aa.h(22) : error C2238: unexpected token(s) preceding ';'
    c:\test\sockertest\aa.h(27) : error C2143: syntax error : missing ';' before '*'
    c:\test\sockertest\aa.h(27) : error C2501: 'CSockertestDlg' : missing storage-class or type specifiers
    c:\test\sockertest\aa.h(27) : error C2501: 'm_socket' : missing storage-class or type specifiers
    sockertestDlg.cpp
    c:\test\sockertest\aa.h(22) : error C2629: unexpected 'class aa ('
    c:\test\sockertest\aa.h(22) : error C2238: unexpected token(s) preceding ';'
    c:\test\sockertest\aa.h(27) : error C2143: syntax error : missing ';' before '*'
    c:\test\sockertest\aa.h(27) : error C2501: 'CSockertestDlg' : missing storage-class or type specifiers
    c:\test\sockertest\aa.h(27) : error C2501: 'm_socket' : missing storage-class or type specifiers
    Generating Code...
    Error executing cl.exe.
      

  2.   

    错误贴错了个,现在这个是刚编译后报的错误:
    MySocket.cpp
    c:\test\sockertest\mysocket.h(23) : error C2629: unexpected 'class MySocket ('
    c:\test\sockertest\mysocket.h(23) : error C2238: unexpected token(s) preceding ';'
    c:\test\sockertest\mysocket.h(24) : error C2143: syntax error : missing ';' before '*'
    c:\test\sockertest\mysocket.h(24) : error C2501: 'CSockertestDlg' : missing storage-class or type specifiers
    c:\test\sockertest\mysocket.h(24) : error C2501: 'std' : missing storage-class or type specifiers
    C:\test\sockertest\MySocket.cpp(19) : error C2511: 'MySocket::MySocket' : overloaded member function 'void (class CSockertestDlg *)' not found in 'MySocket'
            c:\test\sockertest\mysocket.h(15) : see declaration of 'MySocket'
    sockertest.cpp
    c:\test\sockertest\mysocket.h(23) : error C2629: unexpected 'class MySocket ('
    c:\test\sockertest\mysocket.h(23) : error C2238: unexpected token(s) preceding ';'
    c:\test\sockertest\mysocket.h(24) : error C2143: syntax error : missing ';' before '*'
    c:\test\sockertest\mysocket.h(24) : error C2501: 'CSockertestDlg' : missing storage-class or type specifiers
    c:\test\sockertest\mysocket.h(24) : error C2501: 'std' : missing storage-class or type specifiers
    sockertestDlg.cpp
    c:\test\sockertest\mysocket.h(23) : error C2629: unexpected 'class MySocket ('
    c:\test\sockertest\mysocket.h(23) : error C2238: unexpected token(s) preceding ';'
    c:\test\sockertest\mysocket.h(24) : error C2143: syntax error : missing ';' before '*'
    c:\test\sockertest\mysocket.h(24) : error C2501: 'CSockertestDlg' : missing storage-class or type specifiers
    c:\test\sockertest\mysocket.h(24) : error C2501: 'std' : missing storage-class or type specifiers
    Generating Code...
    Error executing cl.exe.
      

  3.   

    你是不是在MySocket这类的头文件里加上CSocketTestDlg的头文件,如果是,改成在MySocket源文件里加头文件,这好象是交叉包括头文件造成的
      

  4.   

    今早醒来问题已找到,,,原来是因为没有在MySocket.h中声明class CSocketTestDlg、、、、
    瞬间石化