C++ friend functions

coder12's Avatar
Newbie Member
can 2 classes have one common friend function?if yes,then how can it be accessed from the classes?(the friend function is defined outside of both the classes)
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Moved to C++ Forum
0
ballurohit's Avatar, Join Date: Nov 2011
Newbie Member
Yes,

A friend function can access the private or publilc members of a class as it were members of those classes.

I would represent the following example though it is not exhaustive.
Code:
     #inclulde <iostream>
  #include <stdlib.h>
   using namespace std;
   class Value
  {
   private:
      int  m_nValue;
   public:
    Value(int nValue) {m_nValue=nVallue;}
   friend bool IsEqual(const Value &cValue1, const Value &cValue2);
};
{
  return (Value1.m_nValue==cValue2.m_nValue);
}

Last edited by shabbir; 21Apr2014 at 19:50.. Reason: Code blocks