1、定义了自己的CClientSocket类和CServerSocket类
2、我要在CTest1Dlg中创建管理这两个类的数组,我想用CArray来做,但是,当我如下使用时
Test1Dlg.h中:
#include "ClientSocket.h"
#include "ServerSocket.h"

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "testView.h"
#include "MyView4.h"
#include "MySplitter.h"
#include "afxdb.h"typedef CArray<CClientSocket,CClientSocket&> CClientArray;
typedef CArray<CServerSocket,CServerSocket&> CServerArray;

/////////////////////////////////////////////////////////////////////////////
// CTest1Dlg dialogclass CTest1Dlg : public CDialog
{
// Construction
public:
CClientArray m_clientGroup;//客户端对象数组
CServerArray m_serverGroup;//服务器端对象数组
CTest1Dlg(CWnd* pParent = NULL); // standard constructor3、它会报如下错误:
c:\documents and settings\administrator\桌面\test1_7\test1dlg.h(17) : error C2143: syntax error : missing ';' before '<'
c:\documents and settings\administrator\桌面\test1_7\test1dlg.h(17) : error C2143: syntax error : missing ';' before '<'
c:\documents and settings\administrator\桌面\test1_7\test1dlg.h(18) : warning C4091: 'typedef ' : ignored on left of 'int' when no variable is declared
c:\documents and settings\administrator\桌面\test1_7\test1dlg.h(18) : error C2143: syntax error : missing ';' before '<'
c:\documents and settings\administrator\桌面\test1_7\test1dlg.h(18) : error C2143: syntax error : missing ';' before '<'
c:\documents and settings\administrator\桌面\test1_7\test1dlg.h(27) : error C2146: syntax error : missing ';' before identifier 'm_clientGroup'
c:\documents and settings\administrator\桌面\test1_7\test1dlg.h(27) : error C2501: 'CClientArray' : missing storage-class or type specifiers
c:\documents and settings\administrator\桌面\test1_7\test1dlg.h(27) : error C2501: 'm_clientGroup' : missing storage-class or type specifiers
c:\documents and settings\administrator\桌面\test1_7\test1dlg.h(28) : error C2146: syntax error : missing ';' before identifier 'm_serverGroup'
c:\documents and settings\administrator\桌面\test1_7\test1dlg.h(28) : error C2501: 'CServerArray' : missing storage-class or type specifiers
c:\documents and settings\administrator\桌面\test1_7\test1dlg.h(28) : error C2501: 'm_serverGroup' : missing storage-class or type specifiers

解决方案 »

  1.   

    加入头文件#include "afxtempl.h"
      

  2.   

    Requirements
    Header: afxtempl.h 
      

  3.   

    1、多谢两位哈,我在CTest1Dlg.h文件中加入了#include <AFXTEMPL.H>,然后就可以编译过去了;
    2、不过我有个疑问,昨天我也注意到这个问题了,然后我是在stdafx.h这个文件中加的上面那个引用,并且在CTest1Dlg.cpp的首部有IDE自动添加的这样一句“#include "stdafx.h"”,这样就编不过去,我不太清楚为什么?
    我的猜测是:“在C++中使用成员变量要提前声明”这个知识点?