我正在使用模板和部分专业化,但有一种专业化我不知道如何编写......我将简化代码以使其更易于阅读。
让我们考虑一下
template <typename T>
class x
{
...
};
通常,我可以这样专攻:
class x<a_type>
{
...
};
也适用于模板类型:
template <typename T>
class x<std::vector<T>>
{
...
}
现在我想对嵌套在模板类中的类型进行专门化:
template <typename T>
class y
{
struct nested_type
{
y a_member;
};
...
};
// Here comes the specialization
template <typename T>
class x<y<T>::nested_type>
{
...
};
这失败了。我还尝试将 'typename' 放在 y::nested_type 之前,但它并没有解决问题。编译器错误是:
type/value mismatch at argument 1 in template parameter list for ‘template <class T> struct x’
我想做的似乎合乎逻辑,但我不确定是否可能。我将 C++0x 与 g++-4.5 一起使用。有人知道编写这种专业化的正确语法吗?