【发布时间】:2010-03-25 23:18:34
【问题描述】:
以下代码产生错误error: ‘struct Foo’ is not a valid type for a template constant parameter:
template <struct Foo>
struct Bar {
};
为什么会这样?
template <class Foo>
struct Bar {
};
工作得很好,甚至可以接受一个结构作为参数。
【问题讨论】:
-
因为 C++ 语言将其定义为这样,
class或typename与typename从我的角度来看更能描述正在发生的事情,否则请尝试用 @987654327 替换它@ 出于某种未知原因...template <typename Foo>表示有一个type,我将调用Foo,它将替换为编译期间使用的实际类型...