Re: [問題] 計程class問題

看板NTUEE110HW作者 (吐司)時間17年前 (2006/11/11 22:43), 編輯推噓5(501)
留言6則, 4人參與, 最新討論串2/2 (看更多)
※ 引述《jackwei (吐司)》之銘言: : employee worker1("Paul","Lin",30000); //parameter是constructor要求輸入的 : //現在想測試一下initial的資料 : cout<<"The employee "<<worker1.getfirstname()<<" " : <<worker1.getlastname()<<"\'s monthly salary is " : <<worker1.getmonsalary()<<endl; : 結果compile的時候他告訴我這邊錯了(cout那行) : 以下是錯誤訊息 : no match for 'operator<<' in 'std::operator<< : [with _Traits = std::char_traits<char>] : (((std::basic_ostream<char, std::char_traits<char> >&)(&std::cout)), : ((const char*)"The employee ")) << (&worker1)->employee::getfirstname()' : 看不懂- -a : 有高手能幫忙解惑嗎 : 謝謝 class employee { public: employee(string name1,string name2,int sry) {fstname=name1; lstname=name2; monsry=sry;} void set() { cout<<"Please enter the employee's first name:"; getline(cin,fstname); cout<<"Please enter the employee's last name"; getline(cin,lstname); cout<<"Please enter the empolyee's monthly salary;"; cin>>monsrytemp; if(monsrytemp>=0)monsry=monsrytemp; else monsry=0; } void getfirstname() { cout<<fstname;} void getlastname() { cout<<lstname;} void getmonsalary() { cout<<monsry;} private: string fstname,lstname; int monsry,monsrytemp; }; -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.240.124 ※ 編輯: jackwei 來自: 140.112.240.124 (11/11 22:49)

11/11 22:52, , 1F
你在cout裡面用了會自己做cout的函式 所以錯誤
11/11 22:52, 1F

11/11 22:54, , 2F
got it thankyou!
11/11 22:54, 2F

11/11 22:59, , 3F
也可以寫string getlastname(){return lstname;}
11/11 22:59, 3F

11/11 23:01, , 4F
一開始的cout就可以這樣用了
11/11 23:01, 4F

11/11 23:03, , 5F
還有這招...謝謝你啦
11/11 23:03, 5F

11/12 01:17, , 6F
哪一行的cout裡面用了會自己做cout的函式 我看不出來..
11/12 01:17, 6F
文章代碼(AID): #15LU6IQA (NTUEE110HW)
討論串 (同標題文章)
文章代碼(AID): #15LU6IQA (NTUEE110HW)