i know there same question topic. i'm still confused. please explain how a's class constructor executing obj inherit a's class constructor privately.
#include <iostream> using namespace std; class a{ public: a(){ cout << "a" << endl; } }; class b:private a{ public: b(){ cout << "b" << endl; } }; int main(){ b obj; return 0; } output
a b
private inheritance means public , protected base members become private in derived class. a::a() private in b, , accessible b::b().
what b::b() can't use private constructors of a (but don't have of those):
struct { public: a(); protected: a(int); private: a(int, int); }; struct derived : /* access irrelevant question */ { derived() : a() {} // ok derived() : a(10) {} // ok derived() : a(1, 2) {} // error, inaccessible };
Comments
Post a Comment