Monday, December 3, 2012

c++ - Ostream from multiple classes - Stack Overflow

I seem to be getting the Error C2440: 'return' cannot convert from 'LinkList' to 'Tray *'. What i'm trying to do is add the output of a second class to that of the customer class. So if i was to call a method such as whoIsEating() i could easily get a list of who, where and what. I had an idea of using 'friend' but i'm quite unsure on that.

Customer.h

class Customer { private:     int tableNumber;     std::string firstName;     std::string lastName;     LinkList<Tray> *myTray; public:     Customer();     Customer(std::string sFirstName, std::string sLastName,         int sTableNumber,         LinkList<Tray> *myTray = new LinkList<Tray>());     ~Customer(void);      int gettableNumber();     Tray* getTray(void); 

Customer.cpp

Tray* Customer::getTray() {     return *myTray; }  ostream& operator << (ostream& output, Customer& customer) {     output << customer.getFirstName() << " " << customer.getLastName() << endl         << customer.gettableNumber() << endl         << (*customer.getTray()) << endl; //Edit: Fixed this     return output; 

Tray.cpp

ostream& operator << (ostream& output, Tray& tray) {     output << "Drink: " << tray.getdrink() << endl;     output << "Food: " << tray.getfood() << endl;     return output; } 

Suspected output would be like

Name: John Smith

Table Number: 12

Meal Details:

Drink: Tea

Food: Fish & Chips

Source: http://stackoverflow.com/questions/13663984/ostream-from-multiple-classes

st bonaventure ncaa tournament 2012 peyton manning 49ers andy pettitte tyler clementi kevin kolb sarah shahi

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.