[英]Class template instantiation as type template parameter, syntax?
class XY{};
template<typename typeA>
class A
{
(...)
};
template<typename typeB>
class B
{
(...)
};
(...)
B<class <class XY>A> * attribute; // <- How can I do that without Syntaxerror
尝试此gcc时,出现以下错误:
xy.h:19:错误:模板参数1无效
我该如何避免呢?
class
关键字仅用于定义模板类,而不用于声明对象。 为此,您只需要:
B<A<XY> >* attribute;
或为了清楚起见将其散布:
typedef A<XY> MyA;
typedef B<MyA> MyB;
MyB* attribute;
您的问题尚不清楚,但我认为您正在追求template template parameters 。 这条路 :
template <template <class> class U>
class Foo {};
现在, Foo
是一个类模板,它接受另一个类模板作为其参数,如下所示:
template <class V>
class Bar {};
Foo<Bar> theFoo;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.