All pastes #1917295 Raw Edit

++ and -- Operator overloading

public cpp v1 · immutable
#1917295 ·published 2010-08-15 09:58 UTC
rendered paste body
//++ and -- Operator overloading#include <iostream.h>#include <process.h>class clock{	int hours, min;	public:		clock(int th, int tm)		{			hours=th;			min=tm;		}		void display()		{			cout<<"\nThe time is "<<hours<<":"<<min;		}		void operator ++() //prefix ovrldng		{			hours++;		}		void operator ++(int temp) //postfix 		{			min++;		}		void operator --() //prefix		{			hours--;		}		void operator --(int temp)//postfix		{			min--;		}};int main(){	clock c(12,0);	int ch;	menu:	c.display();	cout<<"\nMenu:\n1. Advance time by 1 hour\n2. Advance time by 1 minute\n3. Reduce time by 1 hour\n4. Reduce time by 1 minute\n5. Exit\nEnter choice...";	cin>>ch;	switch(ch)	{		case 1:			++c;			break;		case 2:			c++;			break;		case 3:			--c;			break;		case 4:			c++;			break;		case 5:			exit(0);		default:			cout<<"\nInvalid Choice!";			goto menu;	}	goto menu;}