Hi,
I have a simple question to ask.
I was just trying some sample program using friend function.
The program goes like this
Now I get some errors which are fortunate, that I cannot access private members declared in respective classes.
But though I have used friend function why M I getting those errors
Then I just added these two statements in both the classes
It works fine....
Can anyone explain more detail about friend functions....
I'm still not confident about this....
Thankx in advance
I have a simple question to ask.
I was just trying some sample program using friend function.
The program goes like this
Code:
#include<iostream>
using namespace std;
class B;
class A
{
int _x;
public:
A():_x(100){}
~A(){}
friend void funcA(B& b);
};
class B
{
int _y;
public:
B():_y(200){}
~B(){}
friend void funcB(A& a);
};
void funcA(B& b)
{
cout<<b._y<<endl;
}
void funcB(A& a)
{
cout<<a._x<<endl;
}
int main()
{
A a;
B b;
funcA(b);
funcB(a);
return 0;
}
But though I have used friend function why M I getting those errors
Then I just added these two statements in both the classes
Code:
class B;
class A
{
int _x;
public:
A():_x(100){}
~A(){}
friend void funcA(B& b);
friend void funcB(A& a);
};
class B
{
int _y;
public:
B():_y(200){}
~B(){}
friend void funcA(B& b);
friend void funcB(A& a);
};
Can anyone explain more detail about friend functions....
I'm still not confident about this....
Thankx in advance
Comment