14

Possible Duplicate:
What are access specifiers? Should I inherit with private, protected or public?
Difference between private, public and protected inheritance in C++

To all you cpp experts, In c++ inheritance,

class B : public A {
};

I am just curious why is the keyword public needed here? Does it mean something?

Community
  • 1
  • 1
gdlamp
  • 613
  • 1
  • 6
  • 24
  • 6
    Please use google and the SO search bar before asking a question. Read [this](http://stackoverflow.com/questions/860339/difference-between-private-public-and-protected-inheritance-in-c), or if it doesn't explain it to your satisfaction, just search google about C++ inheritance. – Seth Carnegie Jan 10 '12 at 19:59
  • I'm afraid you are not facing any problem here, so it'll probably get closed really soon. You should read the FAQ (http://stackoverflow.com/faq) to know what you should and shouldn't ask here. – talnicolas Jan 10 '12 at 20:00

1 Answers1

17

It means public members in A are inherited by B and are also public from B.

The alternatives are:

  • protected - public members from A are made protected in B, others are kept the same.

  • private - all members from A are made private in B.

The rules don't apply to methods that are hidden or overriden.

Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625