| shmsa | 24-10-2008 03:59 PM | How to use Uniry Operator on class objects using C++ Code:
#include
using namespace std;
class product
{
private:
int count;
public:
void getcount()
{
cout<<"Plz enter the value of count = ";
cin>>count;
}
product (): count(6)
{ }
void operator ++()
{
++count;
cout<<"it is pre increment"<
}
void operator ++(int)
{
count++;
cout<<"it is post increment"<
}
void show()
{
cout<<"the value of count after increment is = "<
}
};
class product1
{
private:
int count;
public:
void getcount()
{
cout<<"Plz enter the value of count = ";
cin>>count;
}
product ()
{count=6;}
void operator --()
{
--count;
cout<<"it is pre decrement"<
}
void operator --(int)
{
count--;
cout<<"it is post decrement"<
}
void show()
{
cout<<"the value of count after decrement is = "<
}
};
void main()
{
product p;
p.getcount();
++p;
p.show();
p.getcount();
p++;
p.show();
product1 p1;
p1.getcount();
--p1;
p1.show();
p1.getcount();
p1--;
p1.show();
} it is done in 2 classes it can also be done in 1 class:bigok: |