Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++11 Destructor = delete

I've seen a constructor = delete explanation here but I'm wondering if I should forbid destructor calls as well. I'm trying to use a class like this:

class A
{
public:
    static bool foo(const char* filePath);
    static void foo(const int something);
private:
    A() = delete;
    ~A();
};

Should I also write like ~A() = delete; as well? Does it even matter?

like image 447
JohnJohn Avatar asked Jan 29 '15 08:01

JohnJohn


1 Answers

~A() = delete; is redundant, because since you cannot create an object, there is no point of worrying about destructor.

In fact with your code even there is no need of A() = delete;, because all the class members are static.
As Luchian rightly mentioned in the comment, such class are better be declared as a namespace. Underlying data can be made extern / static depending on the requirement.

like image 197
iammilind Avatar answered Sep 28 '22 05:09

iammilind