相关疑难解决方法(0)

非类型模板参数

我知道非类型模板参数应该是一个常量整数表达式.有人可以解释为什么会如此?

template <std::string temp>
void foo()
{
     // ...
}
Run Code Online (Sandbox Code Playgroud)
error C2993: 'std::string' : illegal type for non-type template parameter 'temp'.
Run Code Online (Sandbox Code Playgroud)

我理解常量积分表达式是什么.不允许非常量类型的原因是什么,如std::string上面的代码片段?

c++ templates

81
推荐指数
4
解决办法
6万
查看次数

标签 统计

c++ ×1

templates ×1