Pregunta

let's say we have class A,B,C,D where A is base, B,C are between and D is derived in diamond model.

NOTE:

class B inherits virtualy class A in private mode,

class C inherita virtualy class A in protected mode.

class A
{
public:
    int member;  // note this member
};
class B :
    virtual private A // note private 
{

};
class C :
    virtual protected A // note protected
{

};
class D :
    public B, // doesn't metter public or whatever here
    public C
{

};

int main()
{
    D test;
    test.member = 0; // WHAT IS member? protected or private member?
    cin.ignore();
    return 0;
}

now when we make an instance of class D what will member be then? private or protected lol?

Figure No2:

what if we make it so:

class B :
    virtual public A // note public this time!
{

};
class C :
    virtual protected A // same as before
{

};

I suppose member will be public in this second example isn it?

No hay solución correcta

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top