开发者

C++ template types nested in a template class definition

I've a situation where there is a class definition that looks like this:

template<class T>
class Alpha< Bravo<T> >
{
....
};

I'm compiling with gnu g++ and the compiler is complaining that Alpha is, "is开发者_如何转开发 not a template".

I've seen this same technique used in the library that Bravo was written in and Bravo is a templated class. Am I missing something? I've stripped Alpha down to the bone and done testing with no compilation success. I've also tried to copy+paste code from the place I saw this working in Bravo's library and same thing, no success, same error.

Thanks in advance.


What you have there is a partial template specialization; however, any template specialization needs a primary template to specialize, and that you do not have.

template<class T>
class Alpha;

template<class T>
class Alpha<Bravo<T> >
{
    // ...
};


You need to declare a primary template first. What you've written is a specialization.

//primary template - the definition is optional
template<class T>
class Alpha
{
};

//specialization
template<class T>
class Alpha< Bravo<T> >
{
};
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜