我有这个课。
class CItemPriceListTableCache: public cache< TItemPriceListTable >
{
public:
virtual ~CItemPriceListTableCache();
};
我有这个class.cpp:
CItemPriceListTableCache::~CItemPriceListTableCache()
{
}
现在出现问题:
为什么
~CItemPriceListTableCache
函数主体为空?如果我从
class.cpp
中删除,~CItemPriceListTableCache
应该可以吗?会影响我的密码吗?我应该用什么替换~CItemPriceListTableCache
函数体?我只是不喜欢看到空函数。即使我在功能上只有一行适合我,我只是不喜欢功能为空。如果我完成从类中删除析构函数的虚拟声明应该没问题吗?
编辑1:从问题中删除了无用的txt。
编辑2:
类
class DH2KeyAgreement: public KeyAgreement
{
public:
DH2KeyAgreement();
};
class.cpp
DH2KeyAgreement::DH2KeyAgreement() : dh_(), dh2_(dh_)
{
}
我应该在这里使用
default
吗?这样可以罚款吗?
class DH2KeyAgreement: public KeyAgreement
{
public:
DH2KeyAgreement():dh_(), dh2_(dh_)=default;
};
最佳答案
因为不需要对销毁采取任何特殊操作,但是该类的析构函数仍应可调用。
是的,您将遇到未定义的引用错误。
你可以写
virtual ~CItemPriceListTableCache() {}
要么
virtual ~CItemPriceListTableCache() = default;
在类声明中。
是的,编译器生成的默认析构函数就可以了。
关于c++ - 澄清函数体/C++,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37910195/