我了解到:nontypes模板参数
- 无类型模板参数进行一些限制。一般来说,它们可以是常量整数值(包括枚举)或指向具有外部链接的对象的指针。
所以我做了下面的代码
template <char const* name>
class MyClass {
…
};
char const* s = "hello";
MyClass<s> x; // ERROR:
此代码没有工作,产生错误's' is not a valid template argument
我的第二个代码也没有工作
2.
template <char const* name>
class MyClass {
…
};
extern char const *s = "hello";
MyClass<s> x; //error 's' is not a valid template argument`
但奇怪的是这个代码是罚款
template <char const* name>
class MyClass {
…
};
extern char const s[] = "hello";
MyClass<s> x; // OK
请告诉什么是在所有这三个码的发生?
也告诉如何纠正错误,使其他两个代码也工作。
啊,旧的'const *'vs'* const'栗子... – 2012-02-07 08:20:10