Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/160.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++ 函数模板调用未解析_C++_Templates - Fatal编程技术网

C++ 函数模板调用未解析

C++ 函数模板调用未解析,c++,templates,C++,Templates,在下面的代码段中,对max(2,3)的第二个示例调用没有调用该函数。并且没有编译时/运行时错误。 有人能解释一下这是怎么回事吗 template<class T1> void max(int a,int b) { cout<<"max() called\n"; } max<int>(2,3); //this calls max(2,3) max(2,3); //surprisingly no error and max() isn't cal

在下面的代码段中,对
max(2,3)
的第二个示例调用没有调用该函数。并且没有编译时/运行时错误。 有人能解释一下这是怎么回事吗

template<class T1>
void max(int a,int b)
{
        cout<<"max() called\n";
}

max<int>(2,3); //this calls max(2,3)
max(2,3); //surprisingly no error and max() isn't called here
模板
最大无效值(整数a、整数b)
{

cout您没有使用该模板。使用该模板时会出现如下情况:

template<class T1>
void max(T1 a,T1 b)
#include<iostream>
// because the std namespace is not included there will be no shadowing
template<class T1>
void max(T1 a, T1 b)
{
        std::cout<<"max() called\n";
}

模板
最大空隙率(T1 a,T1 b)
在其他一切都相同的情况下,还有另一个函数在std名称空间中隐藏它,将函数名更改为max1将更正此问题或删除名称空间。我希望这会有所帮助

它看起来像这样:

template<class T1>
void max(T1 a,T1 b)
#include<iostream>
// because the std namespace is not included there will be no shadowing
template<class T1>
void max(T1 a, T1 b)
{
        std::cout<<"max() called\n";
}

#包括
//因为没有包含std名称空间,所以不会有阴影
样板
最大空隙率(T1 a,T1 b)
{

std::coutRemove
使用名称空间std;
,您将看到原因(或者不将函数命名为
std
名称空间中存在的函数)应该有一个错误,因为没有定义
cout
。显示真实代码;可以编译的最小代码显示问题。对。这是关于std命名空间的。谢谢