继承期间类的默认可见性模式是什么(此处为D @ class中的B)
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"); }
};
Run Code Online (Sandbox Code Playgroud)
因为当你使用默认的class是private,当你使用默认struct的public.
所以这:
class D2 : B {
Run Code Online (Sandbox Code Playgroud)
相当于
class D2 : private B {
private:
Run Code Online (Sandbox Code Playgroud)
还有这个:
struct D2 : B {
Run Code Online (Sandbox Code Playgroud)
相当于
struct D2 : public B {
public:
Run Code Online (Sandbox Code Playgroud)