64,654
社区成员
发帖
与我相关
我的任务
分享
#include "Tmp.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CTmp::CTmp()
{
}
CTmp::~CTmp()
{
}
template <typename structTmp>
BOOL CTmp::SendTmpl(BYTE emType,typename structTmp)
{
// int len=sizeof(tagSend)+sizeof(typename);
//
// char *szBuffer=new char[len];
// memset(szBuffer,0,len);
// ((tagSend*)szBuffer)->szType = emType;
// memcpy( ( (tagSend*)szBuffer )->szVod,&structTmp ,sizeof(structTmp) );
// int ret=Send( szBuffer,len);
// delete[] szBuffer;
return TRUE;
}
class CTmp
{
public:
CTmp();
virtual ~CTmp();
template <typename structTmp>
BOOL SendTmpl(BYTE emType,typename structTmp);
};
#include <iostream>
#include "Tmp.h"
#include "afx.h"
enum{TLOGIN,TREGISTER};
//通用的发送结构体
struct tagSend{
//TCHAR szType[8];
BYTE szType;
char szVod[1];//内存强制扩充
//void *szVod;
};
//用户登陆结构
struct tagLoginData
{
TCHAR szId[11]; //用户名字
TCHAR szPsw[11];
};
void main()
{
CTmp tmp;
tagLoginData ld;
memset(&ld,0,sizeof(tagLoginData));
strcpy(ld.szId,"admin");
strcpy(ld.szPsw,"admin");
tmp.SendTmpl(TLOGIN,ld);
}
会提示错误:1.obj : error LNK2001: unresolved external symbol "public: int __thiscall CTmp::SendTmpl(unsigned char,struct tagLoginData)" (?SendTmpl@CTmp@@QAEHEUtagLoginData@@@Z) template <typename structTmp>
BOOL SendTmpl(BYTE emType,void *addr, structTmp tmp)
{
int len=sizeof(tagSend)+sizeof(tmp);
char *szBuffer=new char[len];
memset(szBuffer,0,len);
((tagSend*)szBuffer)->szType = emType;
memcpy( ( (tagSend*)szBuffer )->szVod,addr,sizeof(tmp) );
int ret=Send( szBuffer,len);
delete[] szBuffer;
return ret;
}
template <typename structTmp>
BOOL SendTmpl(BYTE emType,typename structTmp)
{
int len=sizeof(tagSend)+sizeof(typename);
char *szBuffer=new char[len];
memset(szBuffer,0,len);
((tagSend*)szBuffer)->szType = emType;
memcpy( ( (tagSend*)szBuffer )->szVod,&structTmp ,sizeof(structTmp) );
int ret=Send( szBuffer,len);
delete[] szBuffer;
return TRUE;
}