That's meant for inheriting the non-default constructors from the parent class, which is A(int i)
in this case. Change your declaration in main like so:
int main()
{
B b(42); // Want to forward this to A::A(int)
...
}
Without the using A::A
clause, you'll get the following compiler error (at least from g++ 4.8.0):
co.cpp: In function ‘int main()’:
co.cpp:20:11: error: no matching function for call to ‘B::B(int)’
B b(42);
^
co.cpp:20:11: note: candidates are:
co.cpp:10:7: note: B::B()
class B : public A
^
co.cpp:10:7: note: candidate expects 0 arguments, 1 provided
co.cpp:10:7: note: constexpr B::B(const B&)
co.cpp:10:7: note: no known conversion for argument 1 from ‘int’ to ‘const B&’
co.cpp:10:7: note: constexpr B::B(B&&)
co.cpp:10:7: note: no known conversion for argument 1 from ‘int’ to ‘B&&’
but if you add the using A::A
declaration back, it compiles cleanly. b(42)
ends up calling A::A(int i)
.