Overloading unary operators using friend function, C/C++ Programming

Overloading Unary Operators Using Friend Function

class sign

{

int a,b,c;

public:

sign(){}; sign(int,int,int); void putdata(void);

friend void operator-(sign &);

};

void operator-(sign &s)

{s.a=-s.a;s.b=-s.b;s.c=-s.c;        }

void sign::putdata(void)

{cout<<"a is: "<<a<<"\n"; cout<<"b is "<"\n"; cout<<"c is "<<c<<"\n";

}

sign::sign(int x,int y, int z)

{a=x;b=y;c=z;                         }

int main()

{sign s; //Implicit constructor calling s=sign(1000,2,10); //Explicit constructor calling s.putdata();

-s;

s.putdata();

cout<<endl;

s=sign(-2000,2,-5);

s.putdata();

-s;

s.putdata();

return 0;

}

Posted Date: 9/20/2012 8:18:47 AM | Location : United States







Related Discussions:- Overloading unary operators using friend function, Assignment Help, Ask Question on Overloading unary operators using friend function, Get Answer, Expert's Help, Overloading unary operators using friend function Discussions

Write discussion on Overloading unary operators using friend function
Your posts are moderated
Related Questions
The task consists of two parts which are both preferably implemented in one source file. Towards the end of this document you will find a code skeleton that you must assume. Start

There is a pebble merchant. He sells the pebbles, that are used for shining the floor. His main duty is to take the length of the room’s sides. But he sometimes mistakes doing that



Object Initialization An object of a derived class can be initialized to an object of a base class. If both the classes have similar data members, then no specific constructor

padovan string c++ program


When declaring a variable of data type pointer, use the * in front of the variable name. These variables hold a memory location (like B45CDF), not an actual value like 30 or A:

Byteland county is very famous for luminous jewels. Luminous jewels are used in making beautiful necklaces. A necklace consists of various luminous jewels of particular colour. Nec

(a) Write a fragment of code that declares a variable colSp of type ColourSpot, and then moves it to the point (3, -4), and sets its colour to Green. (b) A function QU8 is speci