What I was trying to say was
"If there's no reason to call a default constructor, then you shouldn't have a default constructor."
Note also that the compiler will only generate a default constructor for a class if
a.) there are no other user-declared constructors for the class; or
b.) the user explicitly requests a compiler-generated default constructor with
= default.
For example, the following class is not default constructible, because it has a non-default user-declared constructor:
1 2 3 4 5 6 7
|
class Foo
{
public:
Foo(int x, int y, int w, int h);
};
Foo f; // error
| |
Therefore the difference between not mentioning a default constructor at all and defining one as deleted:
1 2 3 4 5 6
|
class Foo
{
public:
Foo() = delete;
Foo(int x, int y, int w, int h);
};
| |
is often just a matter of preference.
By the way, I was missing a
public in my previous post. Sorry if that was misleading.