Hi,
I'm trying to write code such that my class can be used like so:
To accomplish this,
I'm trying to overload the + operator of my class to return a string. I am able to do this, but when I try and do the operation above, I get:
Error: The operation "std::basic_string<char, std::char_traits<char>, std::allocator<char>> + Dan" is illegal.
What does this mean and how do I make it legal?
class Dan
{
public:
string first;
string last;
const string operator + (Dan & a)
{
return a.toString();
}
string toString()
{
return first + ", " + last;
}
....
Dan temp;
string myString = "Test" + temp;