If you look at the code below you can't compile this code.
Code:
#include <iostream>
#include <string>
using std::cout;
using std::endl;
using std::string;
string plus(string x, string y)
{
string a(x);
string b(y);
string c = a + b;
return c;
}
int main()
{
string s1 = "aaa";
string s2 = "bbb";
string s3 = plus(s1, s2);
cout << s3 << endl;
return 0;
}
It gives an error:
Quote:
/usr/include/c++/3.3/bits/stl_function.h: In function `int main()':
/usr/include/c++/3.3/bits/stl_function.h:128: error: `template<class _Tp>
struct std:lus' is not a function,
test2.cc:8: error: conflict with `std::string plus(std::basic_string<char,
std::char_traits<char>, std::allocator<char> >, std::basic_string<char,
std::char_traits<char>, std::allocator<char> >)'
test2.cc:21: error: in call to `plus'
|
Why am i getting this error? If i use an integer version:
Code:
int plus(int x, int y)
{
int z = x + y;
return z;
}
It compiles fine. Why is this strange behavior? Thanks.