this is a similar example to what i have. it's simplified but it still get's the same error.
i need to be able to use << operator to print out all information from class A. i have no idea how to do that. i tried casting it as an A object but then it starts telling me that i can do that with virtual functions. is there any way to go around this?
Code:#include <iostream> #include <string> using namespace std; class A { public: string name; A(string sName) { name = sName; } virtual void mission(); string getName() { return name; } friend ostream& operator << (ostream& out, A& oA) { out << oA.getName() << endl; return out; } }; class B : public A { public: B() : A("bob") { name = "bob"; } }; int main() { B DUDE; cout << DUDE; // this doesnt work either cout << (A)DUDE; return 0; }




Reply With Quote