Recently I have seen a design of a colleague. In such design he came up with a class that looks something like this:
class A {
A() = delete;
A (const std::string &strA, const std::string &strB) noexcept;
}
The thing that itches me is: Does it really make sense here to explicitly delete the 'A()' constructor?
To try to figure out if there where any implications, in the case that such constructor were not explicitly deleted (but it were simply absent), I opened Eclipse and made a test, and it turned out that (in my case) you can completely dismiss the first constructor (keeping the second one), and the compiler will complain if anybody tries to instantiate an object of 'A' without giving the required list of parameters (i.e. "A myA;" or "A myA = A();" ).
Therefore: For which reason(s) is it desirable to explicitly delete the 'A()' constructor, when you will have a constructor (or several constructors) that takes parameters?
Aucun commentaire:
Enregistrer un commentaire