What is the difference between public private and protected inheritance in C

0 votes
In C++, what is the distinction between public, private, and protected inheritance?

All of the inquiries I've read on SO are about particular situations.
Jul 8, 2022 in C++ by Nicholas
• 7,760 points
746 views

1 answer to this question.

0 votes

To begin answering that question, let me characterise member accessors in my own terms. 

If you already know this, proceed to the section "next:".

I'm aware of three types of accessors: public, protected, and private.

Let:

class Base {
    public:
        int publicMember;
    protected:
        int protectedMember;
    private:
        int privateMember;
};

Everything that is aware of Base is likewise aware of the existence of publicMember in Base.

Only the children (and their offspring) are aware that protectedMember exists in Base.

PrivateMember is unknown to everyone except Base.

By "is aware of," I mean "acknowledges the existence of and hence has access to."

next:

The same is true for public, private, and protected inheritance. 

Consider the classes Base and Child, which both inherit from Base.

If the inheritance is made public, everyone who knows about Base and Child is likewise aware that Child is descended from Base.

Only Child and its children are aware that they inherit from Base if the inheritance is protected.

If the inheritance is kept confidential, no one knows about it except Child.

answered Jul 11, 2022 by Damon
• 4,960 points

Related Questions In C++

0 votes
0 answers

What is the difference between std::list<std::pair> and std::map in C++ STL?

What distinguishes std::list<std::pair> from std::map? Does the ...READ MORE

Aug 17, 2022 in C++ by Nicholas
• 7,760 points
616 views
0 votes
0 answers

What is the difference between Java and C++?

What is the difference between Java and ...READ MORE

Jul 22, 2022 in C++ by Nicholas
• 7,760 points
359 views
0 votes
0 answers

What is the difference between cout, cerr, clog of iostream header in c++? When to use which one?

I looked up the differences between cout, ...READ MORE

Jul 27, 2022 in C++ by Nicholas
• 7,760 points
716 views
0 votes
1 answer

What is the difference between std::__gcd and std::gcd?

I done some research about this. The ...READ MORE

answered Jun 10, 2022 in C++ by Damon
• 4,960 points
1,758 views
0 votes
0 answers

What is object slicing?

What is object slicing in C++ and ...READ MORE

Jul 13, 2022 in C++ by Nicholas
• 7,760 points
555 views
0 votes
1 answer

How is inheritance in C++ different than that in Java?

The purpose of inheritance is same for ...READ MORE

answered Feb 6, 2019 in Java by Priyaj
• 58,020 points
977 views
0 votes
1 answer

What is this weird colon-member (" : ") syntax in the constructor?

Foo(int num): bar(num) In C++, this is known as a Member Initializer List. Simply put, it sets the value of your member bar to num. There is a significant difference between initializing a member with the Member initializer list and assigning a value to it within the function Object() { [native code] } body. When you use the Member initializer list to initialise fields, the constructors are only called once, and the object is constructed and initialised in a single operation. If you use assignment, the fields will be initialised with default constructors and then reassigned with actual values (via the assignment operator). As you can see, there is an extra overhead of creation and assignment in the latter, which may be significant for user defined classes. Cost of Member Initialization =Object ...READ MORE

answered May 27, 2022 in Others by Damon
• 4,960 points
1,529 views
0 votes
1 answer

The Definitive C++ Book Guide and List

For Beginner (includes those without coding experience) Programming: ...READ MORE

answered Jun 6, 2022 in C++ by pranav
• 2,590 points
912 views
0 votes
1 answer

What is the difference between operator overloading and operator overriding in C++?

Some people use the latter word to ...READ MORE

answered Aug 2, 2022 in C++ by Damon
• 4,960 points
1,929 views
0 votes
1 answer

C++ code file extension? What is the difference between .cc and .cpp [closed]

GNU GCC recognizes all of the following ...READ MORE

answered Jun 21, 2022 in C++ by Damon
• 4,960 points
1,505 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP