Non capisco perché non sia possibile compilare una classe che ha sia un membro (non di default costruibile) con un inizializzatore brace-or-equal e un costruttore ereditato. g ++ dice:Ereditarietà dei costruttori e inizializzatori bret-or-equal
test.cpp:22:15: error: use of deleted function ‘Derived::Derived(float)’
Derived d(1.2f);test.cpp:16:13: note: ‘Derived::Derived(float)’ is implicitly deleted
because the default definition would be ill-formed:
using Base::Base;test.cpp:16:13: error: no matching function for call to ‘NoDefCTor::NoDefCTor()’
test.cpp:5:1: note: candidate:
NoDefCTor::NoDefCTor(int) NoDefCTor(int) {}
codice che non riesce a compilare (in g ++ 5.1):
struct NoDefCTor
{
NoDefCTor(int) {}
};
struct Base
{
Base(float) {}
};
struct Derived : Base
{
using Base::Base;
NoDefCTor n2{ 4 };
};
int main()
{
Derived d(1.2f);
}
codice che compila, ma mai utilizza costruttore NoDefCTor
s' di default (nonostante quanto pare averne bisogno!):
struct NoDefCTor
{
NoDefCTor(int) {}
NoDefCTor() = default;
};
struct Base
{
Base(float) {}
};
struct Derived : Base
{
using Base::Base;
NoDefCTor n2{ 4 };
};
int main()
{
Derived d(1.2f);
}
Non mi piace l'idea di avere un costruttore predefinito quando non ne ho bisogno. Nota a margine entrambe le versioni compilano (e si comportano) bene su MSVC14.
Questo bug gcc? https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62310 – dyp
Oppure questo bug di gcc? https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67054 – dyp
@dyp grazie. È il secondo bug in effetti. Pensavo fosse una cosa del linguaggio. – maxbc