【发布时间】:2016-06-07 23:02:04
【问题描述】:
我注意到了
template <size_t n, char[n]> class x
{
};
很高兴被我的 C++ 编译器接受。但是,当我天真地尝试类似
x <4, "hey"> something;
我觉得不错
Non type template argument does not refer to any declaration
所以我想知道:我将如何实际使用该模板创建一个类?
【问题讨论】:
-
我的猜测是您的编译器将“hey”的字符串文字视为 const char* 而不是 char[]
-
如果你说
x<5, "hey"> something;,我认为编译器不会在这里强制执行类型安全。