[問題] this 指標

看板C_and_CPP作者 (超囧學生)時間15年前 (2009/06/06 21:17), 編輯推噓2(200)
留言2則, 2人參與, 最新討論串1/2 (看更多)
#include <iostream> #include <cstdlib> using namespace std; class cubic \\定義cubic類別 { private: int a; \\宣告私用成員 a public: cubic(int n) \\設定一個立方函數cubic { a=n*n*n; } cubic cub_sum(cubic b) \\這裡我就不知道幹麼了 { this->a=this->a+b.a; return *this; } int show_date() \\設定輸出資料函數 { cout <<(*this).a<<endl; \\不懂為何有this return 0; } }; int main() \\主函數 { int n1,n2; cin >>n1>>n2; \\宣告跟輸入兩變數 cubic first(n1); cubic second(n2); cubic third(0); \\宣告三個cubic資料型態 third=first.cub_sum(second); \\承接上面 我也不知道幹麼 third.show_date(); \\輸出third的資料 system("pause"); return 0; } 執行就是輸入兩數 會得到立方和 但我不知道立方和哪裡來的??? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 211.74.251.64 ※ 編輯: sarsenwen 來自: 211.74.251.64 (06/06 21:20)

06/06 21:30, , 1F
去看書,書本一定會告訴你 this 是什麼意思
06/06 21:30, 1F

06/06 21:39, , 2F
幫助你搞清楚那個a是哪裡的a
06/06 21:39, 2F
文章代碼(AID): #1AAco1qd (C_and_CPP)
文章代碼(AID): #1AAco1qd (C_and_CPP)