[問題] 作業一問

看板C_and_CPP作者 (神)時間13年前 (2011/01/10 14:27), 編輯推噓1(1011)
留言12則, 6人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, Gcc, Linux, ...) VS2008 額外使用到的庫(Library Used) (Ex: OpenGL, ...)問題(Question): http://codepad.org/uyQlXuIy class Person { private: string Name; Date birthday; <===== 這裡過不了 下面有宣告一個 class Date { private: int year; int month; int day; public: Date() { year = 1911; month = 1; day = 1; } Date(int month, int day, int year) { this->year = year; this->month = month; this->day = day; } }; 因為我呼叫的方法是固定的 Person per1("Andy",Date(1911,2,22)); ^^^^^^^^^^^^^^^ 不知道怎麼改 或是我的寫法完全不行?? 餵入的資料(Input):預期的正確結果(Expected Output): compilar 過 錯誤結果(Wrong Output): compilar 過不了XD 程式碼(Code): (請善用置底文標色功能) http://codepad.org/uyQlXuIy 補充說明(Supplement): -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.118.205.184

01/10 14:28, , 1F
class Date 放在 Person 前面
01/10 14:28, 1F

01/10 16:07, , 2F
就如一樓所說,不過你還有其他問題
01/10 16:07, 2F

01/10 16:07, , 3F
cout<<"Birthday : "<<birthday<<endl;
01/10 16:07, 3F

01/10 16:09, , 4F
謝謝大大幫忙 請問哪邊還有問題呢?
01/10 16:09, 4F

01/10 16:12, , 5F
cout<<birthday 可以改 birthday.year .day 這樣嗎?
01/10 16:12, 5F

01/10 16:34, , 6F
year,month,day 屬性是 private,不能直接這麼做
01/10 16:34, 6F

01/10 16:35, , 7F
簡單方法,可以考慮在Date 多一個 member func,print
01/10 16:35, 7F

01/10 16:47, , 8F
overload operator <<
01/10 16:47, 8F

01/10 16:56, , 9F
overload operator<< +1
01/10 16:56, 9F

01/10 18:24, , 10F
不要用這種標題
01/10 18:24, 10F

01/10 20:38, , 11F
爛標題
01/10 20:38, 11F

01/11 16:15, , 12F
謝謝大大幫忙 因為不知道要下什麼標題..
01/11 16:15, 12F
文章代碼(AID): #1DAgQ-2Z (C_and_CPP)