Suppose we have a class A
:
class A{
int a_;
public:
friend class B;
A(int a):a_(a){}
int getA(){ return a_;}
void setA(int a){a_ = a;}
void print(int x){cout << x << endl;}
};
and another class B
:
class B{
int b_;
public:
B(int b):b_(b){}
void setB(int b){b_ = b;}
int getB(){return b_;}
//friend void A::print(int x);
};
How to use a method of class A like print() using an object of class B?
//main.cpp
B b1(10);
b1.print(b1.getB());