gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 01:43:24 25 4
gpt4 key购买 nike

我有这个类.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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com