Topic: friends
Author: dvw@imonics.com (David Wood - Imonics Development)
Date: 1995/06/21 Raw View
I am trying to use a member function as a friend. The following simple example
seems to be straight forward, yet it will not compile. I used Sparcworks, gcc and
centerline.
Help...
Thanks...
dvw...
=============================================
#include <iostream.h>
class alpha;
class beta;
class ab;
class alpha
{
public:
alpha() { data = 3; };
private:
int data;
friend int add_a_b(alpha,beta);
friend int ab::add_a_b(alpha,beta);
};
class beta
{
public:
beta() { data = 7; };
private:
int data;
friend int add_a_b(alpha,beta);
friend int ab::add_a_b(alpha,beta);
};
class ab
{
public:
int add_a_b(alpha a, beta b)
{
return (a.data + b.data);
};
};
int add_a_b(alpha a, beta b)
{
return (a.data + b.data);
}
int
main()
{
alpha aa;
beta bb;
cout << add_a_b(aa,bb) << endl;
return (0);
}