我似乎收到了错误 C2440:'return' cannot convert from 'LinkList' to 'Tray *'。我想要做的是将第二类的输出添加到客户类的输出中。因此,如果我要调用诸如 whoIsEating() 之类的方法,我可以很容易地得到谁、在哪里和做什么的列表。我有一个使用“朋友”的想法,但我对此不太确定。
客户.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);
客户.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;
托盘.cpp
ostream& operator << (ostream& output, Tray& tray)
{
output << "Drink: " << tray.getdrink() << endl;
output << "Food: " << tray.getfood() << endl;
return output;
}
怀疑的输出就像
姓名:约翰·史密斯
桌数:12
用餐详情:
喝茶
食物:炸鱼薯条