본문 바로가기

PROGRAMMING LANGUAGE/C++

전위연산자,후위연산자의 오버로딩

#include <iostream>
#include <algorithm>
using namespace std;

class CMyData
{
private:
	int m_nData = 0;

public:
	CMyData(int nParam) : m_nData(nParam) {}
	//operator int() { return m_nData; }

	int operator++()
	{
		cout << "operator++()" << endl;
		return ++m_nData;
	}

	int operator++(int)
	{
		cout << "operator++(int)" << endl;
		int nData = m_nData;
		m_nData++;
		return nData;
	}
	
};

int main()
{
	CMyData a(10);
	
	cout << a++ << endl;
	cout << ++a << endl;
	

	return 0;
}