(Note: in C ++ 20, deleting the aggregate constructor now makes the type impossible to build, so there is no more unexpected behavior)
To add other answers here, you can declare the destructor remote, not closed and not implemented. This is because even with a private remote constructor, you can still use aggregate initialization to instantiate:
class A { public: static bool foo(const char* filePath); static void foo(const int something); private: A() = delete; }; int main(){ A a{};
However, if you declare the destructor as remote, neither the default construct nor the initialization of the aggregate will work — it will not compile, because the compiler cannot invoke the destructor for A †
class A { public: static bool foo(const char* filePath); static void foo(const int something); ~A() = delete; }; int main(){ A a{};
Since you have already declared your destructor closed and not implemented, all other things are redundant. C ++ 11 makes it easy that you don't need private , just = delete for the destructor. Explicitly declaring the destructor as remote is preferred because it tells other programmers that you never intended to implement it. Thus, some programmers might think that you just forgot to turn on the implementation.
You will want to declare both the default constructor and the destructor as deleted in order to protect against dynamic memory allocation (via new or new allocation ), because otherwise we will not get a compilation error, because now we need to call delete or explicitly call the destructor . And if it's convenient for us to forget, then everything is fine
class A { public: static bool foo(const char* filePath); static void foo(const int something); ~A() = delete; }; int main(){ A* a = new A();
Posting a new demo
But removing both the constructor and the destructor prevents this:
class A { public: static bool foo(const char* filePath); static void foo(const int something); ~A() = delete; A() = delete; }; int main(){ A* a = new A();
† refer to [class.dtor]: “A program is poorly formed if the potentially called destructor is removed or inaccessible from the call context.”