`
lucane
  • 浏览: 122776 次
  • 性别: Icon_minigender_1
  • 来自: 江湖
社区版块
存档分类
最新评论

call of overloaded ... is ambiguous

阅读更多
照着c++ primer上写的一个函数模板例子
using namespace std;

template <class T>
T min(T a, T b) {
	return a < b ? a : b;
}

int main() {
	cout<<min(10, 32)<<endl;
	cout<<min(24.1, 2.0)<<endl;
	return 0;
}



出现了如下错误:
function_template.cpp: In function `int main()':
function_template.cpp:11: error: call of overloaded `min(int, int)' is 

ambiguous
function_template.cpp:6: note: candidates are: T min(T, T) [with T = int]
D:/Program Files/mingw/MinGW/bin/../lib/gcc/
mingw32/3.4.2/../../../../include/c++/3.4.2/bits/stl_algobase.h:151:
note: const _Tp& std::min(const _Tp&, const _Tp&) 
[with _Tp = std::streamsize]

function_template.cpp:12: error: call of overloaded `min(double, double)' 

is ambiguous
function_template.cpp:6: note: candidates are: T min(T, T) [with T = 

double]
D:/Program Files/mingw/MinGW/bin/../lib/gcc/
mingw32/3.4.2/../../../../include/c++/3.4.2/bits/stl_algobase.h:151:
note: const _Tp& std::min(const _Tp&, const _Tp&) [with _Tp = double]


原因是std中已经有了一个名字叫min的函数(在stl_algobase.h文件的148行),导致名字冲突,
分享到:
评论

相关推荐

    json error: Use of overloaded operator [] is ambiguous错误的解决方法

    然而,当使用C++的`Json::Value`库(如JsonCpp)时,可能会遇到“Use of overloaded operator [] is ambiguous”这样的编译错误。这个错误通常发生在尝试使用0作为数组下标访问`Json::Value`对象时。 在C++中,`[]`...

    C++期末考试重要程序.pdf

    文档中提到了一个编译错误:“[Error] call of overloaded 'Tdate()' is ambiguous”,这表明编译器在解析重载构造函数时产生了歧义。这通常是由于没有明确指定调用哪一个构造函数导致的,需要程序员提供明确的构造...

    VC6到VS2010中的转换

    另一个常见的问题是成员函数无法正常访问,例如出现 `error C2039: 'ReadHuge': is not a member of 'CFile'` 的错误。这通常是由于MFC库在不同版本之间的差异导致的。为了解决这个问题,开发者可以尝试使用替代方法...

    20种VC++编译错误信息

    错误 C2679: binary 'operator': no operator found which takes a right-hand operand of type 'type' (or there is no acceptable conversion) - **描述**:找不到适用于特定类型的二元运算符。 - **原因**: -...

    C++与namespace有关的两个编译错误的讲解

    **错误二:重载调用模糊(call of overloaded ‘fun()' is ambiguous)** 在第二个例子中,我们同时使用了`using namespace A;`和`using namespace B;`,这将`A`和`B`两个命名空间中的所有标识符引入了全局作用域。...

Global site tag (gtag.js) - Google Analytics