作者sarsenwen (超囧學生)
看板C_and_CPP
標題[問題] this 指標
時間Sat Jun 6 21:17:50 2009
#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)
推 littleshan:去看書,書本一定會告訴你 this 是什麼意思 06/06 21:30
推 legendmtg:幫助你搞清楚那個a是哪裡的a 06/06 21:39