samedi 28 novembre 2015

When creating an instance of a derived class, is an instance of the base class being made too? [duplicate]

This question already has an answer here:

When creating an instance of a derived class, is an instance of the base class being made too?

For example:

class a {
public:
    void baz();
    int zxcv = 5;
};

class b: public a{
public:
    void foo();
};

int main(){
    b bar;
    bar.foo();
    bar.baz(); //how can bar have access to baz() if no instance a is created?
    bar.zxcv; //same, how can it access a non static member without an instance?
}

Aucun commentaire:

Enregistrer un commentaire