Thursday, December 13, 2012

friend function in c++


#include<iostream.h>
#include<conio.h>
class Sample
{
  int a,b;
 public:
  void Setvalue()
  {
   a=25;
   b=50;
  }
  friend float mean(Sample S)
};
float mean(Sample S)
{
 return float(S.a+S.b)/2.0;
}
int main()
{
clrscr();
Sample X;
X.Setvalue();
cout<<"mean value="<<mean(X)<<"\n";
getch();
return 0;
}

 Output