我在学习HP Socket 代码的时候 看到一段代码 很纠结 请大牛解惑

lunatic7 lunatic7 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
struct info_msg
{
LPCTSTR name;
CONNID connID;
LPCTSTR evt;
int contentLength;
LPCTSTR content;

static info_msg* Construct(CONNID dwConnID, LPCTSTR lpszEvent, int iContentLength = 0, LPCTSTR lpszContent = nullptr, LPCTSTR lpszName = nullptr);
static void Destruct(info_msg* pMsg);

private:
info_msg(CONNID dwConnID, LPCTSTR lpszEvent, int iContentLength = 0, LPCTSTR lpszContent = nullptr, LPCTSTR lpszName = nullptr);
~info_msg();
};


info_msg* info_msg::Construct(CONNID dwConnID, LPCTSTR lpszEvent, int iContentLength, LPCTSTR lpszContent, LPCTSTR lpszName)
{
return new info_msg(dwConnID, lpszEvent, iContentLength, lpszContent, lpszName);
}

void info_msg::Destruct(info_msg* pMsg)
{
delete pMsg;
}

info_msg::info_msg(CONNID dwConnID, LPCTSTR lpszEvent, int iContentLength, LPCTSTR lpszContent, LPCTSTR lpszName)
: connID(dwConnID), evt(lpszEvent), contentLength(iContentLength), content(lpszContent), name(nullptr)
{
if(lpszName)
{
int len = lstrlen(lpszName);

if(len > 0)
{
name = new TCHAR[len + 1];
memcpy((LPSTR)name, lpszName, (len + 1) * sizeof(TCHAR));
}
}
}

info_msg::~info_msg()
{
if(name)
delete[] name;

if(contentLength > 0)
delete[] content;
}



基础浅薄.实在不懂这是个结构类 数组? 还是模版 迷茫
...全文

相关推荐

评论 6
收藏 已收藏
分享
返回顶部
lunatic7
VC/MFC 16,551 成员 421,605 内容