Hi,
Why I get the errors when using 'friend function'?
// friend function as bridges on two different objects
#include <iostream>
using namespace std;
class alpha
{
private:
int data;
public:
alpha() { data = 3; }
friend int frifunc(alpha, beta); // friend function
};
class beta
{
private:
int data;
public:
beta() { data = 7; }
friend int frifunc(alpha, beta); // friend function
};
int frifunc(alpha a, beta b) // friend function definition
{
return (a.data + b.data);
}
int main()
{
alpha aa;
beta bb;
cout << frifunc(aa,bb);
return 0;
}
When I compile it, the system show me this two errors.
error C2061: syntax error : identifier 'beta'
error C2248: 'data' : cannot access private member declared in class 'alpha'