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 in C++ by Nicholas
• 4,720 points
27 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 by Damon
• 4,760 points

Related Questions In C++

0 votes
0 answers

What is the difference between Java and C++?

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

Jul 22 in C++ by Nicholas
• 4,720 points
12 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 in C++ by Nicholas
• 4,720 points
4 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 in C++ by Damon
• 4,760 points
45 views
0 votes
0 answers

What is the difference between ifstream, ofstream and fstream?

I stumbled discovered ifstream, ofstream, and fstream ...READ MORE

Jul 11 in C++ by Nicholas
• 4,720 points
15 views
0 votes
0 answers

What is object slicing?

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

Jul 13 in C++ by Nicholas
• 4,720 points
14 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,080 points
328 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 in Others by Damon
• 4,760 points
42 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 in C++ by pranav
• 2,580 points
40 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 6 days ago in C++ by Damon
• 4,760 points
12 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 in C++ by Damon
• 4,760 points
12 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP