i know that you can use constructors from a base class in a derived class like
class A {
public:
A() {};
}
class B : public A {
public:
using A::A;
}
Furthermore you can use a constructor from a template base class like
template<typename T>
class A {
public:
A() {};
}
template<typename T>
class B : public A<T> {
public:
using A<T>::A;
}
Suppose that class A now has a template function as constructor:
template<typename T1>
class A {
public:
template<typename T2>
A() {};
}
template<typename T1>
class B : public A<T1> {
public:
using A<T1>::A; // nope
using A<T1>::A<>; // neither
template<typename T2> using A<T1>::A<T2>; // sounds good, doesn't work
}
How could you use the base class constructor in the derived class?
Two things:
template<typename T2> A() {}
is unusuable as a constructor, since there is no way to deduce T2
. Other than that, using A<T1>::A;
is correct.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.