jeudi 28 février 2019

MSVC 19 delete inherited constuctors

Under MSVC 19.16, if class B explicitly inherits from class A the constructors, and also defines his own constructors, the inherited constructors are ignored.

class A {
public:
    A() {}
    A(int x) {}
};

class B : public A {
public:
    using A::A;

    B(double x) : A() {}
};

int main()
{
    B b;                 // error C2512: 'B': no appropriate default constructor available
                         // note: see declaration of 'B'
    return 0;
}

Compiles correctly under gcc. Anyone knows if it is a compiler bug, or something I miss? Thanks.

Aucun commentaire:

Enregistrer un commentaire