protected inheritance

1
2
3
4
5
6
7
8
9
10
11
class Parent{
    public:
        int parentX = 6;
};

class Child :protected Parent{
    public:
        int childX = 5;
};

Parent *parent = new Child;


I'm getting an error because of the protected inheritance.
 
class Child :protected Parent


however public inheritance gives me no error.

Why can't Parent access to Child which is inheriting from protected Parent?
Neither protected nor private inheritance allows you to do

Parent *parent = new Child;

Only public does. Im not really sure why, you can probably find lots of answers on the internet.

However from what Ive heard, public inheritance is by far the most used one.

Edit: Here, Read through this thread :) - http://stackoverflow.com/questions/4619791/public-and-private-inheritance-in-c
Last edited on
Topic archived. No new replies allowed.