Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/135.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用数据类型模板的函数不应该返回long int吗?_C++_Templates - Fatal编程技术网

C++ 使用数据类型模板的函数不应该返回long int吗?

C++ 使用数据类型模板的函数不应该返回long int吗?,c++,templates,C++,Templates,模板参数是从传递的函数参数(但不是返回类型)推导出来的;因此,给定pow(2,50);,数值型被推导为int auto powered = pow(static_cast<long long int>(2), 50); // numeric_type is deduced as long long int 您可以显式指定数字\u类型 auto powered = pow<long long int>(2, 50); // specify numeric_type as

模板参数是从传递的函数参数(但不是返回类型)推导出来的;因此,给定
pow(2,50);
数值型
被推导为
int

auto powered = pow(static_cast<long long int>(2), 50); // numeric_type is deduced as long long int
您可以显式指定
数字\u类型

auto powered = pow<long long int>(2, 50); // specify numeric_type as long long int explicitly

是的,这不起作用。“2”的数字类型是int。使用“2LL”表示长int。这不起作用的原因是2^50太大,无法存储在整数中(它是32位数字,但需要51位才能存储2^50)


auto-powered=pow(2LL,50);

@ArianHassani然后我建议按此答案左侧的绿色勾号,将您的问题标记为已解决。
2LL
将比
静态施法(2)
短。