why the challenge of the function plus ambiguous
-
#include <functional> using namespace std; #define WORD unsigned short void plus(int len, WORD * a, WORD * b, WORD * c); int main(){ WORD M[11],N[11],P[11]; plus(11,M,N,P); } /* Функция вычисляет сумму чисел a и b, результат записывает в c. len - длина числа в словах.*/ void plus(int len, WORD * a, WORD * b, WORD * c) { int i,h=0; long d; for(i=0;i<len;i++) { //d1=a[i]; d=(long)a[i]+b[i]+h; c[i]=(WORD)d&0xffff; h=(d&0x10000l) ? 1 : 0; } }
Please tell me, why is the challenge to function plus is ambigous?
'Cause std:plus accepts two arguments, and here it is defined and transmitted 4
The compiler makes a mistake:
test-ambigous-minus.cpp:7:6: error: reference to 'plus' is ambiguous
plus(11,M,N,P); ^
test-ambigous-minus.cpp:4:10: note: candidate found by name lookup is 'plus'
void plus(int len, WORD * a, WORD * b, WORD * c);
^
/usr/lib/gcc/x86_64-pc-cygwin/4.9.3/include/c++/bits/stl_function.h:167:12: note: candidate found by name lookup is 'std::plus'
struct plus : public binary_function<_Tp, _Tp, _Tp>
^
1 error generated.
-
Because...
std::plus
It's not a function, it's a structure.That's what happened.
namespace std { template<class T> struct plus; } using namespace std; void plus(int len, WORD * a, WORD * b, WORD * c);
That's why it's ambiguous.
You don't have to use it.
using namespace std;
♪