'c++ can i reuse class member's interface as interface, just like reuse base class's member

sometimes we need combine multiple class as a new class, see below:

class A
{
public:
    void SomeHandle();
};
class B;
class C;

each of them provide some useful function,then i need a new class to provide a union of them, so i would write as below:

class Combine
{
public:
    void Combine::SomeHandle();
private:
 A objA;
 B objB;
 C objC;
};

but then i have to write lots of code to rediect call to Combine to corresponding object, like:

void Combine::SomeHandle()
{
    objA.SomeHandle();
}

is there any simpler way expect macro to do that?

c++


Solution 1:[1]

Are you looking for "Inheritance"?

class A
{
public:
   void someHandle();
};

class B:public A
{...
};

allows you to write

B someB;
someB.someHandle();

class B "inherits" all interfaces from class A.

It's a very, very basic feature of OOP.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Hajo Kirchhoff