Saturday, March 19, 2011

Program for Friend Function Using OOPs & C++ concept


#include<iostream.h>
#include<conio.h>
class exforsys
{
               private:
                        int a,b;
               public:
               void test()
               {
                      a=100;
                      b=200;
               }
friend int compute(exforsys e1)
 /* 
Friend Function Declaration with keyword friend and 
with the object of class exforsys to which it is friend passed to it
*/
};
int compute(exforsys e1)
{
                                                    //Friend Function Definition which has access to private data
return int(e1.a+e1.b)-5;
}


void main()
{
exforsys e;
clrscr();
e.test();
cout<<"The result is:"<<compute(e);
//Calling of Friend Function with object as argument.
}

No comments:

Post a Comment