User Tools

Site Tools


c_-_c_operator_overloading:unary_operator_overloading

C - C++ Operator Overloading - Unary operator Overloading

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
 
class space
{
  int x,y,z;
 
public:
  void getdata(int a,int b,int c);
  void display();
  void operator -();
};
 
 
void space::getdata(int a,int b,int c)
{
  x=a;
  y=b;
  z=c;
}
 
 
void space::display(void)
{
  cout<<x<<" "<<y<<" "<<z;
}
 
 
void space::operator -()
{
  x=-x;
  y=-y;
  z=-z;
}
 
 
void main()
{
  clrscr();
  space s;
  s.getdata(10,-20,30);
  -s;
  cout<<"s:";
  s.display();
  getch();
}
c_-_c_operator_overloading/unary_operator_overloading.txt · Last modified: 2020/07/15 09:30 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki