Overload ++ operator for vector class
/*
Objective : Overload ++ operator for vector class
Author: Amit Kumar Trivedi
Ver: 1.0
Date: 10th Sep 2010
Description:

*/

#include <iostream.h>
#include <conio.h>

class Vector
{
	public:
	int x;
	int y;

	void setData(int a, int b)
	{
		x=a;
		y=b;
	}

	Vector(int a, int b)
	{
		x=a;
		y=b;
	}

	void display()
	{
		cout<<"x:"<<x<<endl;
		cout<<"y:"<<y<<endl;
	}
	void operator ++()
	{
		x=x+2;
		y=y+2 ;
	}
	void operator --()
	{
		x=x-2;
		y=y-2;
	}

};

void main()
{
	Vector obj(6,8);
	clrscr();
	obj.display();

	obj++;
	cout<<"After applying ++ operator"<<endl;
	obj.display();
	obj--;
	cout<<"After applying -- operator"<<endl;
	obj.display();
	getch();

}








Overloading Unary Operator Using Member Functions (-,++ and –) in C++ Vector Class

Leave a Reply

Your email address will not be published. Required fields are marked *