C++ C++;:用模板继承类
我通常知道如何用模板继承类。但是当涉及到嵌套类/模板时,我没有任何线索,在互联网上也找不到任何东西(可能是因为我不知道它的关键字)C++ C++;:用模板继承类,c++,templates,inheritance,C++,Templates,Inheritance,我通常知道如何用模板继承类。但是当涉及到嵌套类/模板时,我没有任何线索,在互联网上也找不到任何东西(可能是因为我不知道它的关键字) 模板 甲级; 模板 乙级;; 模板 C2类: 公共C {}; 我希望C2的定义方式与C的定义方式相同,即C2而不是C2。但我不知道任何语法或解决方法如何实现这一点 编辑:T.C.是对的,我希望最终用户只编写C2foo,c2foo不应被允许。这对我来说很有效: template <typename T> class A {}; template <
模板
甲级;
模板
乙级;;
模板
C2类:
公共C
{};
我希望C2
的定义方式与C
的定义方式相同,即C2
而不是C2
。但我不知道任何语法或解决方法如何实现这一点
编辑:T.C.是对的,我希望最终用户只编写C2foo代码>,c2foo代码>不应被允许。这对我来说很有效:
template <typename T>
class A {};
template <class T1, class T2>
class B {};
template < typename T1, class T2>
class C {};
// forward declare C2 but don't define it.
template < typename T1, class T2 > class C2;
// Create the only specialization that depends on using A and B.
template < typename T1, class T2, class T3 >
class C2<A<T1>, B<T2, T3> >: public C< A<T1>, B<T2, T3> >
{};
int main()
{
C2<A<int>, B<double, float>> c1; // OK.
// This creates an instance of the
// only specialization that has
// been defined.
C2<int, double> c2; // Not OK.
// The generic template class has
// been forward declared but has not
// not been defined.
}
模板
A类{};
模板
B类{};
模板
C类{};
//向前声明C2,但不定义它。
模板<类型名T1,类别T2>类别C2;
//创建唯一依赖于使用A和B的专门化。
模板
C2类:公共C
{};
int main()
{
C2;//好的。
//这将创建
//只有专业化
//已经定义。
C2;//不正常。
//泛型模板类具有
//已转发声明,但尚未转发
//没有定义。
}
这对我很有用:
template <typename T>
class A {};
template <class T1, class T2>
class B {};
template < typename T1, class T2>
class C {};
// forward declare C2 but don't define it.
template < typename T1, class T2 > class C2;
// Create the only specialization that depends on using A and B.
template < typename T1, class T2, class T3 >
class C2<A<T1>, B<T2, T3> >: public C< A<T1>, B<T2, T3> >
{};
int main()
{
C2<A<int>, B<double, float>> c1; // OK.
// This creates an instance of the
// only specialization that has
// been defined.
C2<int, double> c2; // Not OK.
// The generic template class has
// been forward declared but has not
// not been defined.
}
模板
A类{};
模板
B类{};
模板
C类{};
//向前声明C2,但不定义它。
模板<类型名T1,类别T2>类别C2;
//创建唯一依赖于使用A和B的专门化。
模板
C2类:公共C
{};
int main()
{
C2;//好的。
//这将创建
//只有专业化
//已经定义。
C2;//不正常。
//泛型模板类具有
//已转发声明,但尚未转发
//没有定义。
}
这对我很有用:
template <typename T>
class A {};
template <class T1, class T2>
class B {};
template < typename T1, class T2>
class C {};
// forward declare C2 but don't define it.
template < typename T1, class T2 > class C2;
// Create the only specialization that depends on using A and B.
template < typename T1, class T2, class T3 >
class C2<A<T1>, B<T2, T3> >: public C< A<T1>, B<T2, T3> >
{};
int main()
{
C2<A<int>, B<double, float>> c1; // OK.
// This creates an instance of the
// only specialization that has
// been defined.
C2<int, double> c2; // Not OK.
// The generic template class has
// been forward declared but has not
// not been defined.
}
模板
A类{};
模板
B类{};
模板
C类{};
//向前声明C2,但不定义它。
模板<类型名T1,类别T2>类别C2;
//创建唯一依赖于使用A和B的专门化。
模板
C2类:公共C
{};
int main()
{
C2;//好的。
//这将创建
//只有专业化
//已经定义。
C2;//不正常。
//泛型模板类具有
//已转发声明,但尚未转发
//没有定义。
}
这对我很有用:
template <typename T>
class A {};
template <class T1, class T2>
class B {};
template < typename T1, class T2>
class C {};
// forward declare C2 but don't define it.
template < typename T1, class T2 > class C2;
// Create the only specialization that depends on using A and B.
template < typename T1, class T2, class T3 >
class C2<A<T1>, B<T2, T3> >: public C< A<T1>, B<T2, T3> >
{};
int main()
{
C2<A<int>, B<double, float>> c1; // OK.
// This creates an instance of the
// only specialization that has
// been defined.
C2<int, double> c2; // Not OK.
// The generic template class has
// been forward declared but has not
// not been defined.
}
模板
A类{};
模板
B类{};
模板
C类{};
//向前声明C2,但不定义它。
模板<类型名T1,类别T2>类别C2;
//创建唯一依赖于使用A和B的专门化。
模板
C2类:公共C
{};
int main()
{
C2;//好的。
//这将创建
//只有专业化
//已经定义。
C2;//不正常。
//泛型模板类具有
//已转发声明,但尚未转发
//没有定义。
}
我已经看过你的问题好几次了,但我真的不明白你在问什么。首先:如何定义C
?您的意思是希望最终用户编写C2foo代码>而不是C2 foo代码>?如果他们编写c2foo代码>模板类别C2;/*未定义的*/模板类C2:公共C{/*定义*/}代码>您可能可以将它与静态断言和类型特征()一起破解,尽管我真的不确定。我也不认为这样做有什么意义。我已经读了你的问题好几次了,但我真的不明白你在问什么。首先:如何定义C
?您的意思是希望最终用户编写C2foo代码>而不是C2 foo代码>?如果他们编写c2foo代码>模板类别C2;/*未定义的*/模板类C2:公共C{/*定义*/}代码>您可能可以将它与静态断言和类型特征()一起破解,尽管我真的不确定。我也不认为这样做有什么意义。我已经读了你的问题好几次了,但我真的不明白你在问什么。首先:如何定义C
?您的意思是希望最终用户编写C2foo代码>而不是C2 foo代码>?如果他们编写c2foo代码>模板类别C2;/*未定义的*/模板类C2:公共C{/*定义*/}代码>您可能可以将它与静态断言和类型特征()一起破解,尽管我真的不确定。我也不认为这样做有什么意义。我已经读了你的问题好几次了,但我真的不明白你在问什么。首先:如何定义C
?您的意思是希望最终用户编写C2foo代码>而不是C2 foo代码>?如果他们编写c2foo代码>模板类别C2;/*未定义*/模板类C2:公共