How do I declare a method as "friend"?
Basically I have 2 classes under a namspace, and I want to give one of the
methods of one class (call it B::fun) access to the private member of the
other class (call it class A). However, I can't seem to get it to work.
Here is a simple example that illustrates the problem:
namespace ABC // this could be global too
{
class A;
class B
{
int fun(A member);
};
class A
{
public:
friend int B::fun(A member);
private:
int aint;
};
int B::fun(A member)
{
return member.aint;
}
}
Why do I get this error?
No comments:
Post a Comment