class CFruit {
private:
string m_name;
public:
string getName() const;
CFruit(string name = "NoName");
};
The fruitsalad is represented in the class CFruitSalad:
class CFruitSalad {
//Overloaded Operators
friend ostream& operator <<(ostream& out, const CFruitSalad& f);
friend CFruitSalad operator +(const CFruit& f1, const CFruit& f2);
private:
string m_fruitsalad;
public:
CFruitSalad(string content = "");
string getName() const;
};
Now when I use write this:
CFruit f1("Apple");
CFruit f2("Orange");
CFruit f3 ("Banana");
CFruitSalad fs;
fs = f1 + f2 + f3; //this line generates the error
cout << "Content: " << fs << endl;
When compiled the program the following error is received: error C2678: binary '+' : no operator found which takes a left-hand operand of type 'CFruitSalad' (or there is no acceptable conversion)
Why does this error occur and how to solve it?