c++ - 澄清函数体/C++

标签 c++

我有这个类.h:

class CItemPriceListTableCache: public cache< TItemPriceListTable >
{
public:
    virtual ~CItemPriceListTableCache();    
};

我有这个 class.cpp :

CItemPriceListTableCache::~CItemPriceListTableCache()
{

}

现在问题来了: 为什么 ~CItemPriceListTableCache 函数体是空的? 如果我从 class.cpp 中删除 ~CItemPriceListTableCache 应该没问题?会影响我的代码吗?我应该用什么替换 ~CItemPriceListTableCache 函数体?我只是不喜欢看到空函数。即使我在函数中只有一行对我来说没问题,我只是不喜欢函数为空。 如果我完成从类中删除析构函数的虚拟声明应该可以吗?

编辑 1:从问题中删除无用的 txt。

编辑 2: 类.h

class DH2KeyAgreement: public KeyAgreement
{
public:
    DH2KeyAgreement();
};

类.cpp

DH2KeyAgreement::DH2KeyAgreement() : dh_(), dh2_(dh_)
{

}

我应该如何在这里使用 default

这样可以吗?

class DH2KeyAgreement: public KeyAgreement
{
public:
    DH2KeyAgreement():dh_(), dh2_(dh_)=default;
};

最佳答案

Why is ~CItemPriceListTableCache funtion body empty ?

因为不需要对销毁采取特殊操作,但析构函数仍然应该为此类调用。

If i delete from class.cpp the ~CItemPriceListTableCache should be ok ? Will affect this my codes ?

是的,您将留下一个 undefined reference 错误。

With what should i replace ~CItemPriceListTableCache function body ? I just don't like to see empty functions. Even if i have one line in function is ok for me , i just don't like function to be empty.

你可以写

virtual ~CItemPriceListTableCache() {}

virtual ~CItemPriceListTableCache() = default;

在你的类声明中。

If i complete delete virtual decalaration of destructor from class should be ok ?

是的,编译器生成的默认析构函数就可以了。

关于c++ - 澄清函数体/C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37910195/

相关文章:

c++ - 在仿真代码中使用全局变量

c++ - 尝试向文件添加扩展名时,Rename() 函数不起作用

具有动态项目大小的 C++ vector

c++ - 系统范围的 ShellExecute Hook ?

c++ - 在 C++ 中对多个链接数组进行排序

c++ - Xcode 4(或 3)iOS,带 C++

c++ - 我如何更改样本计数或使用 gprof 进行频率调整? 10.0 毫秒太多了 ubuntu.c++

c++ - 返回值的完美转发?

c++ - 如何将动态分配的内存释放到结构内的数组?

c++ - 为什么这个自动矢量化器关心构造函数/析构函数?