作业:
运算符号重载实现。
struct Person
{
public:int x;int y;
public:Person(){this->x = 10;this->y = 20;}Person(int x, int y){this->x = x;this->y = y;}//申明友元函数void Printf(const Person& p){printf("%d %d",p.x,p.y);}//友元函数重载Person operator + (const Person& p);Person operator - (const Person& p);Person operator * (const Person& p);Person operator / (const Person& p);bool operator >(const Person& p);bool operator <(const Person& p);bool operator >=(const Person& p);bool operator <=(const Person& p);bool operator ==(const Person& p);};Person Person:: operator + (const Person & p )
{this->x =this->x + p.x;this->y = this->y + p.y;return *this;
}
Person Person:: operator - (const Person& p)
{this->x = this->x - p.x;this->y = this->y - p.y;return *this;
}
Person Person:: operator * (const Person& p)
{this->x = this->x * p.x;this->y = this->y * p.y;return *this;
}
Person Person:: operator / (const Person& p)
{this->x = this->x / p.x;this->y = this->y / p.y;return *this;
}bool Person ::operator >(const Person& p)
{if (this->x > p.x && this->y > p.y){return true;}return false;
}
bool Person ::operator <(const Person& p)
{if (this->x < p.x && this->y< p.y){return true;}return false;
}
bool Person ::operator >=(const Person& p)
{if (this->x >= p.x && this->y >= p.y){return true;}return false;
}
bool Person ::operator <=(const Person& p)
{if (this->x <= p.x && this->y <= p.y){return true;}return false;
}
bool Person ::operator ==(const Person& p)
{if (this->x == p.x && this->y == p.y){return true;}return false;
}
2 引用和指针的区别
x = (int*)10;
00592EB1 mov dword ptr [x],0Ah
指针修改指向生成的反汇编代码。
引用
x = 10;
00591A01 mov eax,dword ptr [x]
00591A04 mov dword ptr [eax],0Ah
引用是不可能出现修改指向的反汇编代码的。
这也就是反汇编中唯一能看出来的瑕疵。