I have a class "c" which has instances of classes "a" and "b" as its properties. I want to access methods of object A in object B. Currently, I defined a method in class b that wraps the "add" method of class a and added class a as a property of class b. Is there a better OOP way of accessing class a's methods in class b.
#include <iostream>
class a
{
public:
a(){i = 1; j = 2;}
int add() { return i + j; }
private:
int i;
int j;
};
class b
{
public:
b() {}
int add() { return k + l; }
int adda() { return A.add(); }
private:
int k;
int l;
a A;
};
class c
{
public:
int add() { return A.add() + B.add(); }
int addainb() { return B.adda(); }
private:
a A;
b B;
};
int main()
{
c C;
int res = C.addainb();
std::cout << res << std::endl;
return 0;
}