Your Ad Here

Saturday, July 21, 2007

Operator Overloading,Inheritance

Here's a simple and also a very short program in C++ that makes use of Constructors, Operator Overloading (++,--)and Single Inheritance (cause its a simple program as I mentioned it).......


/* C++ Program For Implementation Of Constructors, Operator Overloading and Inheritance */

class index
{
protected:
int count;
public:
index()
{
count = 0;
}
index(int c)
{
count = c;
}
index operator ++()
{
count++;
}
void display()
{
cout< < endl< < "count = "< < count< < endl;
}
};

class index1 : public index
{
public:
void operator --()
{
count--;
}
};

void main()
{
clrscr();
index1 i;
i++;
i++;
i.display();
i--;
i.display();
getch();
}

6 comments:

Unknown said...

Thank you............

panku said...

really it helps a lot,and easy to understand...

Anonymous said...

void main() is incorrect, it's on the FAQ of Bjarne Stroustrup's website.

main() is an integer returning function, it can cause your operating system problems if not.

nupur said...

thnx...really helped me a lot

karthi said...

thank you

Tariq said...

thanks.
this is simple and easy to understand

Your Ad Here