读书人

使用CArray时遇到的一个编译有关问题

发布时间: 2012-05-01 12:48:58 作者: rapoo

使用CArray时遇到的一个编译问题
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 dialog

class CTest1Dlg : public CDialog
{
// Construction
public:
CClientArray m_clientGroup;//客户端对象数组
CServerArray m_serverGroup;//服务器端对象数组CTest1Dlg(CWnd* pParent = NULL);// standard constructor



3、它会报如下错误:
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

[解决办法]
加入头文件

#include "afxtempl.h"

读书人网 >VC/MFC

热点推荐