inheritance private

is it possible to inherit private elements of the base class.

I mean inheriting the private elements, (not private inheritance, were base class elements become private in the inheriting class)
The answer to what I think you're asking is "no". The whole point of 'private' is that nothing else can access it.

If you want something your children can have access to, make it 'protected' instead.

(Although technically you do inherit private elements, you just can't access them)
it turns out with inheritance, everything is inherited apart from constructors
private elements can be accessed from the inheriting class. you need to use a function though
Yeah I think I misunderstood your question.

You're right. Everything is inherited except for ctors, dtors, and I think the assignment operator.

Although children cannot access private elements. Using a function just sidesteps that because then the children aren't accessing the members directly, the function is.
Best way is to inherit private then using the "using" declarative to select what functions or members that should be available.

Example::

1
2
3
4
5
6
7
8
9
10
class A {
  private:
    int a;
    void foo();
}
class B : private A {
  private:
    using A::a;
    using A::foo();
}
Topic archived. No new replies allowed.