#include <iostream>
using namespace std;
class ThreeD {
int x, y, z;
public:
ThreeD() { x = y = z = 0; }
ThreeD(int i, int j, int k) {x = i; y = j; z = k; }
ThreeD operator++(int notused); // postfix version of ++
void show() ;
} ;
// Show X, Y, Z coordinates.
void ThreeD::show()
{
cout << x << ", ";
cout << y << ", ";
cout << z << "\n";
}
ThreeD ThreeD::operator++(int notused)
{
ThreeD temp = *this; // save original value
x++; // increment x, y, and z
y++;
z++;
return temp; // return original value
}
int main()
{
ThreeD a(1, 2, 3);
cout << "Original value of a: ";
a.show();
a++; // increment a
cout << "Value after ++a: ";
a.show();
return 0;
}
Original value of a: 1, 2, 3
Value after ++a: 2, 3, 4