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

Overloading Unary Operators Using Friend Function

class sign


int a,b,c;


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();








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
Problem Statement: You have to write a C program to develop a Car Parking Management System for a busy commercial area. The system will record the car plate number, date and time w

Write a Program that illustrate creation of a data file? Here is a program to generate a Fibonacci series and write it into a Data file. # include main() { FILE *fpt;

Op e r a t o r O v e r l o a d i n g : W h e n   a n   o p e r a t o r   i s   u s e d   f o r   d i ff e r e n t   op e r a

Protected derivation In addition to doing private and public derivations, you may also do a protected derivation. In this situation :   The private members inherited

Write a program to count the prime number in array

Aim: Write a program of multipication using inline function class Multiply {           int x,y;           public:           void getdata();           inline calc

count the number of string in n-th padovan string

# include stdio.h> # include conio.h> # include math.h>   void main () { int a=1,sqr=0,cube=0; clrscr (); while (a { sqr=pow(a,2); cube=pow(a,3);

A palindrome is a string that reads the same from both the ends. Given a string S convert it to a palindrome by doing character replacement. Your task is to convert S to palindrome

In this lab, please complete a given program to perform the following tasks: 1. Allocate a 10 by 5 2D byte array dynamically. The way of allocation must be consistent with page