C++ 从依赖模板的基类继承构造函数

C++ 从依赖模板的基类继承构造函数,c++,templates,inheritance,C++,Templates,Inheritance,如果基类的名称依赖于(派生类的)模板参数,如何继承基类的构造函数 例如: #include <type_traits> struct A { }; struct B { }; template <bool Abase> struct C : public std::conditional_t<Abase, A, B> { using std::conditional_t<Abase, A, B>::(std::conditional_

如果基类的名称依赖于(派生类的)模板参数,如何继承基类的构造函数

例如:

#include <type_traits>

struct A {
};

struct B {
};

template <bool Abase>
struct C : public std::conditional_t<Abase, A, B> {
    using std::conditional_t<Abase, A, B>::(std::conditional_t<Abase, A, B>); // Error!
}

int main()
{
    C<true> c;
    C<false> c2;
}
#包括
结构A{
};
结构B{
};
模板
结构C:public std::conditional\u t{
使用std::conditional\u t:(std::conditional\u t);//错误!
}
int main()
{
C C;
c2;
}
在程序中,
struct C
应继承
A::A
B::B
,具体取决于模板参数
bool Abase
的值。 程序在编写时不会编译


正确的语法是什么?

您可以先定义类型别名

template <bool Abase>
struct C : public std::conditional_t<Abase, A, B> {
    using base = std::conditional_t<Abase, A, B>;
    using base::base;
};
模板

使用std::conditional\u t的结构C:public std::conditional\u t

),尽管这很奇怪。