Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c++ inheritance syntax [duplicate]

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?

like image 662
gdlamp Avatar asked Jan 10 '12 19:01

gdlamp


People also ask

Which is the correct syntax of inheritance in C?

Correct choice is (c) class derived_classname : access base_classname{ /*define class body*/ }; The explanation is: Firstly, keyword class should come, followed by the derived class name.

Does C allow multiple inheritance?

Master C and Embedded C Programming- Learn as you go So the class can inherit features from multiple base classes using multiple inheritance. This is an important feature of object oriented programming languages such as C++.

What is the syntax of multiple inheritance?

Syntax of Implementing Multiple Inheritance in C++ Description of the syntax: access_modifier: It provides the access modifier in the class declaration as it specifies how the derived class is inheriting the base class. base_class: There can be over one base class, from which the derived class inherits its properties.

What is the syntax of inheritance?

The Syntax for Inheritance in C++The keyword class: Just like defining any usual class in C++, which requires a keyword class, defining a subclass also follows a similar syntax. Name of the subclass: You have to specify the name of the sub-class or the derived class that inherits the properties of some other class.


1 Answers

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.

like image 109
Luchian Grigore Avatar answered Oct 22 '22 12:10

Luchian Grigore