4

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"); }
};
Daniel Frey
  • 55,810
  • 13
  • 122
  • 180
Saransh
  • 109
  • 1
  • 8

1 Answers1

8

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:
Daniel Frey
  • 55,810
  • 13
  • 122
  • 180
  • private: in class body and public: in struct body are unnecessary as it is a default – 4pie0 Oct 19 '13 at 11:01
  • @piotruś Did you read the question and do you realize that I was trying to show what is the default? Of course I have to repeat what is superfluous to show that! – Daniel Frey Oct 19 '13 at 11:04
  • the OP asked about what is the default inheritance mode, so if class A : B is equivalent to class A : public B or maybe class A : private B or anything else. The default qualifier inside the class definition is another issue, however I agree it is advisable to mention too – 4pie0 Oct 19 '13 at 11:08