What would be the syntax to inherit constructors (some of them are template) from a class template in C++11 ?
template <class T>
struct Base
{
using type = T;
explicit constexpr Base(const type& x): value{x} {};
template <class U> explicit constexpr Base(U&& x): value{std::forward<U>(x)} {};
type value;
}
struct Derived: Base<bool>
{
using Base::Base<bool>; // Does not seem to work ?!?
}
You derive from Base<bool>. So your base class is Base<bool>, and inheriting the constructors is done via
using Base<bool>::Base;
Live on Coliru
You do not need Base<bool> after the ::, in fact the code doesn't compile if you put it. The constructors are still referred to as Base, and not Base<bool>. This is consistent with referring to member functions of class templates: you use e.g. void Foo<int>::f() and not void Foo<int>::f<int>() to refer to the Foo's member function f().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With