|
From: DC A <ad...@ho...> - 2007-03-08 12:57:14
|
If you look at the code below you can't compile this code(gnu c++).
#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:
/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:plus' 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'
Here plus is a function outside of any namespace. Also plus is a structure
defined inside std namespace. so why can't compiler compile the above code?
What's wrong?
Thanks.
_________________________________________________________________
Your Space. Your Friends. Your Stories. Share your world with Windows Live
Spaces. http://spaces.live.com/?mkt=en-ca
|