Exposing member variables methods in C++

c++, c++11

Solution

Not directly, no. You could use private inheritance to inherit from the components instead of aggregating them (note that private inheritance does not express is-a), and then publish some of their member functions by `using`. Something like this:

class Object1 : public Object, private Component1, private Component2, ..., private ComponentN
{
public:
  using Component1::function1();
  using Component1::function2();
  ...
  using ComponentN::functionM();
};

I'm not saying it's necessarily the best way to do it, but it's a way.

Problem

I have a simple `Object-Components` design. Something like: ``` class Object1 : public Object { Component1 _comp1; Component2 _comp2; ... ComponentN _compN; }; ``` Is it possible to expose as `public:` methods of `Objects1` some methods from `ComponentK` without creating a method in `Object1` that calls internally `ComponentK` method? I need a simple way of doing this because it's quite annoying to write a function every time I want to expose some `ComponentK` method.

Original source