C++ 模板不明确错误

c++ template ambiguous error

本文关键字:错误 不明确 C++      更新时间:2023-10-16

这是我的代码,试图简单地添加 2 个数字。

#include <iostream>
#include <string>
using namespace std;
template<class first, class second>
first plus(first x, second y) {
return x + y;
}
int main() {
int a = 123;
int b = 21;
plus(a, b);
return 0;
}

plus(( 给了我一个错误,指出它是"模棱两可的"。这基本上是我在模板上的教程中看到的复制代码(它在哪里工作!(,所以我现在真的很困惑。

删除using namespace std,您正在与std::plus发生冲突

http://en.cppreference.com/w/cpp/utility/functional/plus

我已经解决了删除 std 命名空间或更改函数名称的问题!