Saturday 2 October 2010

The unary minus operator using friend function



The unary minus operator using friend function

<header files>
class A
{
int x;
A(int=0);
public:
friend A operator –(A);
};
A  operator –(A Aobj)
{
return A(-Aobj .x);
}
void main()
{
int y;
A a1, a2;
cout<<”Enter the value of y”;
cin>>y;
a2.x=x;
a1= -a2;
cout<<a1.x
}



friend function

No comments:

Post a Comment