C++ Programming Blog

 
 
 

Image

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

class minus
{
  int d1,d2,d3;
  public:
  minus()
  {d1=d2=d3=0;}
  minus(int a,int b,int c)
  {
   d1=a;
   d2=b;
   d3=c;
  }
  void display(void)
  {
    cout<<d1<<\"  \"<<d2<<\"  \"<<d3;
  }
  void operator - ()
  {
    d1=-d1;
    d2=-d2;
    d3=-d3;
  }
};

void main()
{
  clrscr();
  minus o1,o2(2,4,6);

  -o1;
  cout<<\"\\nData of Object 1 : \";
  o1.display();

  -o2;
  cout<<\"\\n\\nData of Object 2 : \";
  o2.display();

getch();
}

 
 
Didn't find what you were looking for? Find more on Program that implements overloaded - minus unary operator.