J
Juha Nieminen
Consider this:
#include <iostream>
#include <string>
std::string operator+(const char* a, const std::string& b)
{
return std::string(a)+b;
}
int main()
{
std::string s = "abc" + "def";
std::cout << s << std::endl;
}
With gcc 3.3.5 it gives the rather strange error:
test.cc:11: error: invalid operands of types `const char[4]' and `const
char[4]
' to binary `operator+'
If I substitute the offending line with this:
std::string s = "abc" + std::string("def");
or even with this:
std::string s = operator+("abc", "def");
then it works just ok. However, as given above it doesn't. How come?
(References to the C++ standard preferred.)
#include <iostream>
#include <string>
std::string operator+(const char* a, const std::string& b)
{
return std::string(a)+b;
}
int main()
{
std::string s = "abc" + "def";
std::cout << s << std::endl;
}
With gcc 3.3.5 it gives the rather strange error:
test.cc:11: error: invalid operands of types `const char[4]' and `const
char[4]
' to binary `operator+'
If I substitute the offending line with this:
std::string s = "abc" + std::string("def");
or even with this:
std::string s = operator+("abc", "def");
then it works just ok. However, as given above it doesn't. How come?
(References to the C++ standard preferred.)