728x90
#include <iostream>
using namespace std;

class Power {
	int kick;
	int punch;
public:
	Power(int kick = 0, int punch = 0) { this->kick = kick; this->punch = punch; }
	void show();
	friend Power& operator++(Power& op); 
	Power operator++ (int x);
};

void Power::show() {
	cout << "kick=" << kick << ',' << "punch=" << punch << endl;
}

Power& operator++(Power& op) { 
	op.kick++;
	op.punch++;
	return op; 
}

Power Power::operator++(int x) {
	Power tmp = *this; 
	kick++;
	punch++;
	return tmp; 
}


int main() {
	cout << "2018305065 전유정" << endl << endl;
	Power a(3, 5), b;
	b = ++a; 
	a.show(); 	b.show();

	b = a++;
	a.show(); 	b.show();
}

반응형
  • 네이버 블러그 공유하기
  • 네이버 밴드에 공유하기
  • 페이스북 공유하기
  • 카카오스토리 공유하기