C++ 重載負號

#include <iostream>
using namespace std;

class test {
private:
	int x;
	int y;
public:
	test(int xx = 0, int yy = 0)
	{
		x = xx;
		y = yy;
	};
	test  operator- (void)
	{
		this->x = -this->x;
		this->y = -this->y;
		return *this;
	};
	void show(void)
	{
		cout<<"x = "<<x<<endl;
		cout<<"y = "<<y<<endl;
	}
};

int main(int argc, char * argv[])
{
	test a(1, 1);
	a = -a;
	a.show();
	system("pause");
	return 0;
}

蛋疼的寫下來。。

怎麼樣重載負號。。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章