inheritance and operator<<
Hello,
I've got this problem; probabily about inheritance:
Code:
class Fruit { }
class DriedFruit : public Fruit { }
class Walnut : public DriedFruit {
float _kCalories;
public:
Walnut (float cal = 0) : _kCalories(0) { }
~Walnut() { }
friend std::ostream& operator<<(std::ostream& os, Walnut& w) {
return os << "provence = " << "\t" << "protein = " << w._kCalories<< endl;
}
};
//main.cpp
Fruit* f = new Walnut;
cout << *f;
//error
error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'Fruit' (or there is no acceptable conversion)
//and many others....
Any hints, please?