我在编写自助餐厅模拟项目时遇到了另一个问题。这个想法是我正在编写三个类(学生、组和托盘)和一个主程序来模拟一个正在运行的自助餐厅。托盘包含某些信息,例如颜色和拿起它的学生的姓名,以及托盘上的食物加起来的总量。在每个托盘与一个学生配对后,它被推入一个组堆栈。这就是问题出现的地方。尝试使用托盘定义组函数时出现各种错误论据。以下是这两个类的代码以及一些错误,再次,我将不胜感激:
class group
{
public:
//CONSTRUCTOR
group(string color="nocolor"){group_color=color; group_total=0;}
//MEMBER FUNCTIONS for group class:
void set_color(string new_color){group_color=new_color;}
void add_member(simic_217A::tray new_member){assert(group_color==new_member.color());members.push(new_member);group_total+=new_member.price();}
//void add_it_up();
void remove_one() {members.pop();}
void empty_group(){assert(!members.empty()); while(!members.empty()){members.pop();}} // NEWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWw
//CONST MEMBER FUNCTIONS for group class:
string color() const {return group_color;}
double price_tot() const {assert(!members.empty()); return group_total;}
bool is_empty() const {return members.empty();}
simic_217A::tray top_item() const {return members.top();}
private:
double group_total;
string group_color;
stack<simic_217A::tray> members;
};
//NONMEMBER FUNCTION for group class:
std::ostream& operator <<(std::ostream& outs, const group& info);
class tray
{
public:
//CONSTRUCTOR
tray(string color="nocolor"){tray_color=color; tray_student_name="noname"; tray_price=0;}
//MEMBER FUNCTIONS for tray class:
void pick_up(student nextinline){tray_student_name= nextinline.get_name(); tray_price= nextinline.price(); nextinline.set_group(tray_color) ;}
string set_color(string color){tray_color=color;}
void drop_tray(){tray_student_name="noname"; tray_price=0;}
//CONST MEMBER FUNCTION for tray class:
string tray_name() const {return tray_student_name;}
double tray_price_func() const {return tray_price;}
string color () const {return tray_color;}
private:
string tray_color;
string tray_student_name;
double tray_price;
};
}
以下是我在尝试编译时遇到的几个错误:
error C2039: 'tray' : is not a member of 'simic_217A'
error C2061: syntax error : identifier 'tray'
error C2146: syntax error : missing ';' before identifier 'top_item'