【发布时间】:2011-08-26 22:54:58
【问题描述】:
这是我的代码:
template<typename T, template<typename = T,typename =std::allocator<typename = T> > class Container= std::vector>
class stack
{
public:
Container<T> cont;
stack()
{
}
};
如果我将第一行代码替换为下面的代码,那么它可以工作:
template<typename T, template<typename elem= T,typename =std::allocator<elem> > class Container= std::vector>
但我想问一下,当您不使用模板类型参数时,我已经阅读过,那么您可以这样写:<typename=default_type> 或 <typename>。此外,上述代码中的T 在模板模板参数Container 的参数列表中可见(即类型参数T 在其整个参数化子句中可见)。所以总而言之,我认为它应该可以工作。
但它没有并给出错误:
error: expression '<erroneous-expression> = <erroneous-expression>' is not a constant-expression
error: template argument 1 and 2 are invalid
那么任何人都可以解释为什么我会看到这些错误,什么是错误表达?
【问题讨论】:
-
"erroneous-expression" 可能只是你的编译器被混淆了。