Complete the code to declare a class B that inherits publicly from class A.
class B : [1] A {};
Using public inheritance means all public members of A remain public in B.
Complete the code to make class B inherit privately from class A.
class B : [1] A {};
Private inheritance means all public and protected members of A become private in B.
Fix the error in the code to allow class B to access protected members of class A.
class A { protected: int x; }; class B : [1] A { public: void setX(int val) { A::x = val; } };
Public inheritance allows B to access protected members of A.
Fill both blanks to declare class B that inherits protectedly from class A and class C that inherits publicly from B.
class B : [1] A {}; class C : [2] B {};
Class B inherits protectedly from A, so A's public and protected members become protected in B.
Class C inherits publicly from B, so B's protected members remain protected in C.
Fill all three blanks to create a class D that inherits publicly from B and privately from C, where B inherits publicly from A and C inherits protectedly from A.
class B : [1] A {}; class C : [2] A {}; class D : [3] B, private C {};
B inherits publicly from A, so A's public members stay public in B.
C inherits protectedly from A, so A's public and protected members become protected in C.
D inherits publicly from B, so B's public members stay public in D, and privately from C, so C's members become private in D.