0x00 用到的知识点
类的封装、有參构造函数、引用、 this指针
0x01 代码
class Number
{
public:
Number(){}
public:
Number(const int& iValue) {
this->m_Value = iValue;
}
public:
/*两个数相比较大小
const Number& obj 比较数实例
返回值:
-1 比比较数小
0 相等
1 比比较数大
*/
int CompareNumber(const Number& obj)
{
int retValue;
if(this->m_Value > obj.m_Value)
{
retValue = 1;
}
else if (this->m_Value < obj.m_Value)
{
retValue = -1;
}
else if (this->m_Value == obj.m_Value)
{
retValue = 0;
}
return retValue;
}
private:
int m_Value;
};
int main()
{
Number intValueA(10);
Number intValueB(20);
auto iRes = intValueA.CompareNumber(intValueB);
cout << iRes << endl;
return 0;
}