不好意思,一口氣丟出這麼多的問題出來
我對於指標以及this的用法,有些不太瞭解。
以下的例子內
敘述為
int Compare(CBox xBox)
{
return this->Volume() > xBox.Volume();
}
請問這一行的目的是?
謝謝
附上完整的語法
#include <iostream>
using namespace std;
class CBox
{
public:
CBox(double lv = 1.0, double bv = 1.0, double hv = 1.0): m_Length(lv),
m_Breadth(bv),
m_Height(hv)
{
cout << endl << "Constructor called.";
}
double Volume()
{
return m_Length*m_Breadth*m_Height;
}
int Compare(CBox xBox)
{
return this->Volume() > xBox.Volume();
}
private:
double m_Length;
double m_Breadth;
double m_Height;
};
int main()
{
CBox match(2.2, 1.1, 0.5);
CBox cigar(8.0, 5.0,1.0);
if(cigar.Compare(match))
cout << endl
<< "match is smaller than cigar";
else
cout << endl
<< "match is equal to or larger than cigar";
cout << endl;
return 0;
}
--
┌─────◆KKCITY◆─────┐ ◢ ◤ 找歌最方便 KKBOX 歌詞搜尋!!
│ bbs.kkcity.com.tw │ \^_^ / ★http://www.kkbox.com.tw★
└──《From:140.109.139.91 》──┘ ◤ 唱片公司授權,音樂盡情下載
--