滴水逆向_引用_友元函数_运算符重载

作业:

运算符号重载实现。

复制代码
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  

引用是不可能出现修改指向的反汇编代码的。

这也就是反汇编中唯一能看出来的瑕疵。

相关推荐
起个昵称吧20 小时前
立即数、栈、汇编与C函数的调用
c语言·开发语言·汇编
mysla2 天前
嵌入式学习day46-硬件—汇编
汇编·学习
zgc12453672 天前
汇编基础2
汇编
出门吃三碗饭3 天前
编译器构造:从零手写汇编与反汇编程序(一)
android·汇编
JCBP_3 天前
QT(3)
开发语言·汇编·c++·qt·算法
出门吃三碗饭3 天前
编译器构造:模拟器,汇编与反汇编
汇编
zgc12453673 天前
汇编基础1
汇编·学习
sheepwjl3 天前
《嵌入式硬件(六):ARM汇编核心内容总结》
汇编·arm开发·嵌入式硬件
武文斌774 天前
ARM工作模式、汇编学习
汇编·嵌入式硬件·学习·arm
mysla4 天前
嵌入式学习day45-硬件—汇编
汇编·学习