Don't use the habit of putting classes together through inheritance, mixing and matching classes that do just about what you want. This leads to terrible code.
However, sometimes it makes sense to implement one class using another. In these cases, if you use inheritance, the โrightโ way to do this is to use private inheritance.
And by โright,โ I mean the most acceptable way.
class A { public: void f1() { cout << "function 1"; } void f2() { cout << "function 2"; } void f3() { cout << "function 3"; } }; class B: private A { public: using A::A;
The time when this may make sense is when the composition is too tedious due to the number of methods used.
Galik source share