The following code compiles:
struct A {
A(int xx) : x(xx) {}
int x;
};
struct B : A {
using A::A;
};
int main() {
B b(5); // OK. The constructor taking an int is available
return 0;
}
The following code does not:
struct A {
A() {}
A(const A &) {}
};
struct B : A {
using A::A;
};
int main() {
A a;
B b; // No complaint about this line
B c(a); // No constructor taking const A & is available.
return 0;
}
Why is it that the constructor of A
is made available in the first case, but not in the second?
EDIT (following being marked as duplicate):
The answer to the question to which this one is suspected to be a duplicate states (bold is suggested by the comment):
For each non-template constructor in the candidate set of inherited constructors [..], a constructor is implicitly declared with the same constructor characteristics unless there is a user-declared constructor with the same signature in the complete class where the using-declaration appears or the constructor would be a default, copy, or move constructor for that class.
This does not seem to answer my question, since the constructor taking a const A &
argument would not be a copy constructor for B
.