简体   繁体   English

类模板实例化为类型模板参数,语法?

[英]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

When trying this gcc gives me the following error: 尝试此gcc时,出现以下错误:

xy.h:19: error: template argument 1 is invalid xy.h:19:错误:模板参数1无效

How can I avoid that? 我该如何避免呢?

The class keyword is only for defining a template class, not for declaring an object. class关键字仅用于定义模板类,而不用于声明对象。 For that, you just need: 为此,您只需要:

B<A<XY> >* attribute;

Or to spread it out for clarity: 或为了清楚起见将其散布:

typedef A<XY> MyA;
typedef B<MyA> MyB;
MyB* attribute;

Your question is quite unclear, but I think you're after template template parameters . 您的问题尚不清楚,但我认为您正在追求template template parameters This way : 这条路 :

template <template <class> class U>
class Foo {};

Now Foo is a class template accepting another class template as its parameter, like so : 现在, Foo是一个类模板,它接受另一个类模板作为其参数,如下所示:

template <class V>
class Bar {};

Foo<Bar> theFoo;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM