partially private inheritance?

Is there a way to make only some of the base class members private while leaving the rest public?
Declare the private ones in the private section, and the public ones in the public section. There's also protected access too.

If your program is around long enough you'll eventually see that you should never access class data directly, but thru methods whos access is managed in this way with all data being private.
do this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

class A
{
  public:
    int a;       //These are publics, can be accessed by every class
    void foo();

   protected:
    int b;   //Protected, accessed by only this class or its child.
   private:
   int c;   //this item will be private. can't be accessed outside this class (except by friends)
};

class B : public A
{
  //Your code goes here
};
If you want some of the public members of the base class not being available use a syntax like:
class Base
{
public:
void func1();
...
protected:
...
private:
...
};

class Derived : public A
{
...
private:
using Base::func1(); //this will be private in your class Derived
...
};

that way you can achieve deciding which member function you wish to provide to your Derived class.

Also you can split your Base class into 2 and inherit one as public and the other privately. I wouldn't recommend this though as multiple inheritance opens new fields and probably causes some more trouble than it solves (determining the structure of each base class etc)
Topic archived. No new replies allowed.