相关疑难解决方法(0)

C-Style Strings作为模板参数?

C样式字符串可以用作模板参数吗?

我试过了:

template <char *str>
struct X
{
    const char *GetString() const
    {
         return str;
    }
};

int main()
{
    X<"String"> x;
    cout<<x.GetString();
}
Run Code Online (Sandbox Code Playgroud)

虽然我没有对类定义抱怨,但实例化产生'X' : invalid expression as a template argument for 'str'(VC).

c++ string templates

53
推荐指数
5
解决办法
7万
查看次数

标签 统计

c++ ×1

string ×1

templates ×1