gpt4 book ai didi

c++ - 模板参数字符串与 int

转载 作者:太空狗 更新时间:2023-10-29 19:44:09 26 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Strings as template arguments?

为什么第一个声明可以,但第二个声明不行?为什么 std::string 不合适?

template <typename T, T x> struct foo { };

using namespace std;

int main()
{
foo<int, 0> f_int; // ok
foo<string, ""> f_string; // not ok
}

我得到:

error: a non-type template parameter cannot have type 'std::basic_string<char>'

使用 clang++。

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com