http://www.cplusplus.com/reference/functional/negate/
std空间已经有了negate这个名字了
C:\VisualStudioProjects\C++\C++>cat main.cpp
#include<iostream>
using namespace std;
int negate(const int &val);
int main()
{
int v = 15;
cout << v << " negate is " << negate(v) << endl;
return 0;
}
int negate(const int &val)
{
return -val;
}
C:\VisualStudioProjects\C++\C++>g++ main.cpp
main.cpp: In function 'int main()':
main.cpp:9:32: error: reference to 'negate' is ambiguous
cout << v << " negate is " << negate(v) << endl;
^~~~~~
main.cpp:4:5: note: candidates are: int negate(const int&)
int negate(const int &val);
^~~~~~
In file included from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/string:48:0,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/locale_classes.h:40,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/ios_base.h:41,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/ios:42,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/ostream:38,
from /usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/iostream:39,
from main.cpp:1:
/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/stl_function.h:162:12: note: template<class _Tp> struct std::negate
struct negate;
^~~~~~
C:\VisualStudioProjects\C++\C++>vim main.cpp
C:\VisualStudioProjects\C++\C++>cat main.cpp
#include<iostream>
//using namespace std;
int negate(const int &val);
int main()
{
int v = 15;
std::cout << v << " negate is " << negate(v) << std::endl;
return 0;
}
int negate(const int &val)
{
return -val;
}
C:\VisualStudioProjects\C++\C++>g++ main.cpp
C:\VisualStudioProjects\C++\C++>
|