问题描述
大家好,
我有一段这样的代码
构造函数:
IPCClientDataTransfer :: IPCClientDataTransfer(RWCString serviceName):有效(FALSE)
{
NSTcpProfile tcpProfile;
int clientPriority = 1;
tcpProfile。 BlockingOnConnect = TRUE;
tcpProfile.Blocking = TRUE;
strcpy(tcpProfile.ServiceName,serviceName);
strcpy(tcpProfile.TcpHostName," ; localhost");
this - > PClient =新的IPCAMAClient(& tcpProfile,clientPriority);
//检查IPCAMAClient是否是有效对象
if(!this - > ; PClient - > isValid())
{
//对象无效,连接未建立
删除此 - > ; PClient;
this - > PClient = NULL;
}
else
{
//对象有效
this - >有效= TRUE;
}
析构函数:
IPCClientDataTransfer :: ~IPCClientDataTransfer()
{
if(this - > PClient)
删除此 - > PClient;
}
析构函数不是虚拟的。这意味着会有内存泄漏吗?
Hi all,
I have a piece of code like this
constructor:
IPCClientDataTransfer::IPCClientDataTransfer (RWCString serviceName) :Valid(FALSE)
{
NSTcpProfile tcpProfile;
int clientPriority = 1;
tcpProfile.BlockingOnConnect = TRUE;
tcpProfile.Blocking = TRUE;
strcpy(tcpProfile.ServiceName, serviceName);
strcpy(tcpProfile.TcpHostName, "localhost");
this -> PClient = new IPCAMAClient (&tcpProfile, clientPriority);
// Check to see if the IPCAMAClient is a valid object
if (!this -> PClient -> isValid())
{
// The object is invalid, the connection was not established
delete this -> PClient;
this -> PClient = NULL;
}
else
{
// The Object is valid
this -> Valid = TRUE;
}
destructor:
IPCClientDataTransfer::~IPCClientDataTransfer ()
{
if (this -> PClient)
delete this -> PClient;
}
the destructor is not virtual.does this means that there will be memory leak?
推荐答案
这篇关于如何使用虚拟析构函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!