Entry
how can we access private data member or member function of one class to another ?
Nov 22nd, 2006 03:01
praveen tripathi, praveen tripathi
we can simply access data member or member function from one class to
another:
we can make friend to both classes.
suppose i have to access private member of class 'a'in class 'b'
we will define friend class 'a' inside class 'b'.
for example:-
class a
{
friend class b;
private:
int v1;
};
class b
{
public:
void inita()
{
a some_a;
// Here we access the private member variable v1
// in A as if it were public
some_a.v1 = 10;
}
};