テストは奇妙な動作を示します ( c++14
、g++ 4.9.1
、clang 3.5.5
):
要約すると:
B
使用できる他のコンストラクターがない場合A::A()
B
他のコンストラクタを提供する場合は使用できませんA::A()
が、 を使用しますA::A(whatever arguments)
。これは予期しない動作です (少なくとも私にとっては)。
セットアップ 1:
struct A {
A() {};
A(int) {}; // with or without this overload the result are the same
};
struct B : A {
using A::A;
};
B b0{}; // OK
セットアップ 2:
struct A {
A() {}; // with a default constructor instead (empty class A)
// the results are the same
};
struct B : A {
using A::A;
B(int){}
};
B b0{}; // no matching constructor
B b1{24}; // OK
セットアップ 3:
struct A {
A() {};
A(int) {};
};
struct B : A {
using A::A;
B(int, int){}
};
B b0{}; // no matching constructor
B b1{24}; // OK
B b2{24, 42}; // OK
なぜこれが起こっているのか、どのように「修正」できますか。