Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c++ inheritance visibility mode

what is the default visibility mode of classes during inheritance (here for B in D@ class)

class B {
public:
    int key;
    B(void) { key = 0; printf("B constructed\n");}
    virtual void Tell(void);
    ~B(void) {cout <<"B destroyed"<<endl << endl;}
};


class D2 : B {
public:
    void Tell(void) { printf("D2 Here\n"); }
};
like image 494
Saransh Avatar asked Sep 17 '25 05:09

Saransh


1 Answers

The default for when you use class is private, the default for when you use struct is public.

So this:

class D2 : B {

is equivalent to

class D2 : private B {
private:

and this:

struct D2 : B {

would be equivalent to

struct D2 : public B {
public:
like image 184
Daniel Frey Avatar answered Sep 18 '25 17:09

Daniel Frey