2012-05-11 9 views
1

私はカフェテリアシミュレーションプロジェクトを書く際に別の問題に遭遇しました。私は3つのクラス(の学生、グループ、トレイ)と、実行中のカフェテリアをシミュレートするメインプログラムを書いているという考えがあります。 トレイには、色とそれをピックアップする学生の名前との名前と、トレイ上の食品の合計量などの情報が保持されています。それぞれトレイ生徒とペアになった後、それはグループスタックにプッシュされます。これが問題の原因です。 グループの機能をトレイ引数で定義しようとすると、さまざまなエラーが発生します。下の2つのクラスのコードだけでなく、多少の誤差があり、再び、私は、任意の洞察力をいただければ幸いです。ここクラスをヘッダファイルの別のクラスの値の型として使用する

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' 

答えて

関連する問題