[問題] this 指標
#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
06/06 21:30, 1F
推
06/06 21:39, , 2F
06/06 21:39, 2F
討論串 (同標題文章)
完整討論串 (本文為第 1 之 2 篇):
問題
2
2