我不知道CList怎么定义,在网络上看了很多内容,但是还是不能解决自己的问题,希望高手解决下面是头文件MyQQServerDlg.h// MyQQServerDlg.h : header file
//#include "Afxtempl.h"
#include "resource.h"
#include "ListenSocket.h"
#include "ClientSocket.h"
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
/////////////////////////////////////////////////////////////////////////////
// CMyQQServerDlg dialogclass CMyQQServerDlg : public CDialog
{
// Construction
struct SServerMsg
{
UINT m_msgtype;
char m_msgBuff[2048];
};
struct SUserInfo
{
UINT m_infoID; //用户帐号
char m_infoNick[64]; //用户昵称
char m_infoName[64]; //用户姓名
UINT m_infoPSW; //用户密码
UINT m_infoAge; //用户年龄
UINT m_infoSex; //用户性别
UINT m_infoPicture; //用户头像
UINT m_infoIsOnLine; //用户在线状态
UINT m_infoFriendList[64];//好友名单,最多可设定64为好友
UINT m_infoBlackList[16];//黑名单,最多可设定16为黑名单
char m_infoAddr[20]; //用户IP地址
UINT m_infoPort; //用户端口
void *m_infoSocket; //用户服务器端的SOCKET指针 UINT m_infoTime; //记录用户上次保持连接的时间
};public:protected:private:
BOOL m_IsServerOn;
CListenSocket m_listenSocket;
UINT m_iServerPort;
CString m_strServerIP;
UINT m_iTotalUser;
UINT m_iActiveUser;
UINT m_MAXID;
CList<SUserInfo,SUserInfo> m_lstAllUser;
CList<CClientSocket,CClientSocket> m_lstSocket;
};编译错误如下:
Compiling...
ClientSocket.cpp
c:\program files\microsoft visual studio\vc98\mfc\include\afxtempl.h(1064) : error C2664: 'struct __POSITION *__thiscall CList<class CClientSocket,class CClientSocket>::AddTail(class CClientSocket)' : cannot convert parameter 1 from 'class CClientSo
cket' to 'class CClientSocket'
No copy constructor available for class 'CClientSocket'
c:\program files\microsoft visual studio\vc98\mfc\include\afxtempl.h(1566) : while compiling class-template member function 'void __thiscall CList<class CClientSocket,class CClientSocket>::Serialize(class CArchive &)'
ListenSocket.cpp
c:\program files\microsoft visual studio\vc98\mfc\include\afxtempl.h(1064) : error C2664: 'struct __POSITION *__thiscall CList<class CClientSocket,class CClientSocket>::AddTail(class CClientSocket)' : cannot convert parameter 1 from 'class CClientSo
cket' to 'class CClientSocket'
No copy constructor available for class 'CClientSocket'
c:\program files\microsoft visual studio\vc98\mfc\include\afxtempl.h(1566) : while compiling class-template member function 'void __thiscall CList<class CClientSocket,class CClientSocket>::Serialize(class CArchive &)'
MyQQServerDlg.cpp
F:\聊天室\MyQQServer\MyQQServerDlg.cpp(273) : error C2664: 'struct __POSITION *__thiscall CList<class CClientSocket,class CClientSocket>::AddTail(class CClientSocket)' : cannot convert parameter 1 from 'class CClientSocket *' to 'class CCli
entSocket'
No constructor could take the source type, or constructor overload resolution was ambiguous
不知如何解决,请求解决
//#include "Afxtempl.h"
#include "resource.h"
#include "ListenSocket.h"
#include "ClientSocket.h"
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
/////////////////////////////////////////////////////////////////////////////
// CMyQQServerDlg dialogclass CMyQQServerDlg : public CDialog
{
// Construction
struct SServerMsg
{
UINT m_msgtype;
char m_msgBuff[2048];
};
struct SUserInfo
{
UINT m_infoID; //用户帐号
char m_infoNick[64]; //用户昵称
char m_infoName[64]; //用户姓名
UINT m_infoPSW; //用户密码
UINT m_infoAge; //用户年龄
UINT m_infoSex; //用户性别
UINT m_infoPicture; //用户头像
UINT m_infoIsOnLine; //用户在线状态
UINT m_infoFriendList[64];//好友名单,最多可设定64为好友
UINT m_infoBlackList[16];//黑名单,最多可设定16为黑名单
char m_infoAddr[20]; //用户IP地址
UINT m_infoPort; //用户端口
void *m_infoSocket; //用户服务器端的SOCKET指针 UINT m_infoTime; //记录用户上次保持连接的时间
};public:protected:private:
BOOL m_IsServerOn;
CListenSocket m_listenSocket;
UINT m_iServerPort;
CString m_strServerIP;
UINT m_iTotalUser;
UINT m_iActiveUser;
UINT m_MAXID;
CList<SUserInfo,SUserInfo> m_lstAllUser;
CList<CClientSocket,CClientSocket> m_lstSocket;
};编译错误如下:
Compiling...
ClientSocket.cpp
c:\program files\microsoft visual studio\vc98\mfc\include\afxtempl.h(1064) : error C2664: 'struct __POSITION *__thiscall CList<class CClientSocket,class CClientSocket>::AddTail(class CClientSocket)' : cannot convert parameter 1 from 'class CClientSo
cket' to 'class CClientSocket'
No copy constructor available for class 'CClientSocket'
c:\program files\microsoft visual studio\vc98\mfc\include\afxtempl.h(1566) : while compiling class-template member function 'void __thiscall CList<class CClientSocket,class CClientSocket>::Serialize(class CArchive &)'
ListenSocket.cpp
c:\program files\microsoft visual studio\vc98\mfc\include\afxtempl.h(1064) : error C2664: 'struct __POSITION *__thiscall CList<class CClientSocket,class CClientSocket>::AddTail(class CClientSocket)' : cannot convert parameter 1 from 'class CClientSo
cket' to 'class CClientSocket'
No copy constructor available for class 'CClientSocket'
c:\program files\microsoft visual studio\vc98\mfc\include\afxtempl.h(1566) : while compiling class-template member function 'void __thiscall CList<class CClientSocket,class CClientSocket>::Serialize(class CArchive &)'
MyQQServerDlg.cpp
F:\聊天室\MyQQServer\MyQQServerDlg.cpp(273) : error C2664: 'struct __POSITION *__thiscall CList<class CClientSocket,class CClientSocket>::AddTail(class CClientSocket)' : cannot convert parameter 1 from 'class CClientSocket *' to 'class CCli
entSocket'
No constructor could take the source type, or constructor overload resolution was ambiguous
不知如何解决,请求解决
最好改成
CList <CClientSocket*,CClientSocket*> m_lstSocket;
你的CClientSocket类并不支持拷贝构造
'class CClientSo cket' to 'class CClientSocket'
No copy constructor available for class 'CClientSocket'
在其他地方我有用到跟这个有关的程序,如下:
void CMyQQServerDlg::OnAccept()
{
CClientSocket *m_clientSocket=new CClientSocket;
m_clientSocket->SetParent(this);
m_listenSocket.Accept(*m_clientSocket);
m_lstSocket.AddTail(m_clientSocket); SServerMsg msg;
msg.m_msgtype=001;
sprintf(msg.m_msgBuff,"%s","服务器运行正常!"); m_clientSocket->Send(&msg,sizeof(SServerMsg));}
如果 不这么做 劝你不要做WINDOWS 程序了