-3

I don't understand and i really don't get public vs private inheritance in classes. Suppose we have the following code:

class A {
    int A_a;
protected:
    int A_b;
public:
    int A_c;
};
class B : public A {
    int B_a;
protected:
    int B_b;
public:
    int B_c;
};

class C : private A {
    int C_a;
protected:
    int C_b;
public:
    int C_c;
};

I know it has to be with access rights over vars and funcs, but doing all the tests i really can grasp it and i don't know when to apply public or private inheritance;

Lucas
  • 329
  • 1
  • 8
  • 1
    This is not a site for explaining the basic semantics of a programming language - that's what textbooks are for. Which C++ textbook are you using? –  Oct 31 '18 at 22:38
  • Sorry, i know. But my english in sometimes missleading and im using this old book in pdf "Object-Oriented Programming in C++, Fourth Edition". – Lucas Oct 31 '18 at 23:27

1 Answers1

-1

Here is simple sheme (base class -> derived clas) how visibility of class members change with different types of inheritance:

Public inheritance:

  • public -> public
  • protected -> protected
  • private -> private

Protected inheritance:

  • public -> protected
  • protected -> protected
  • private -> private

Private inheritance:

  • public -> private
  • protected -> private
  • private -> private

Here you have few simple examples https://www.tutorialspoint.com/cplusplus/cpp_inheritance.htm

SloCompTech
  • 116
  • 1
  • 7