vendredi 27 juillet 2018

Why does 'A a{};' compile when the default constructor A::A() is deleted?

Here's the code example in question:

struct A {
    A() = delete;
};

int main()
{
//  A a(); // compiles, since it's a function declaration (most vexing parse)
//  A a;   // does not compile, just as expected
    A a{}; // compiles, why? The default constructor is deleted.
}

Try it here with any of the available compilers. I tried with several and didn't find one that gave a compilation error.

Aucun commentaire:

Enregistrer un commentaire