我看过一个constructor = delete的解释here但我想知道我是否也应该禁止析构函数调用。我正在尝试使用这样的类:
class A
{
public:
static bool foo(const char* filePath);
static void foo(const int something);
private:
A() = delete;
~A();
};
我是否也应该像 ~A() = delete;
这样写?这有关系吗?
最佳答案
~A() = delete;
是多余的,因为您不能创建对象,所以不必担心析构函数。
事实上,对于您的代码,甚至不需要A() = delete;
,因为所有类成员都是static
。
正如 Luchian 在评论中正确提到的那样,这样的 class
最好声明为 namespace
。底层数据可以根据需要做成extern
/static
关于C++11 析构函数 = 删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28210382/