“a struct has public inheritance by default” what does this statement really mean? And why is the following code in error just because I have omitted the keyword ‘public’ while deriving the class d from c??
struct c
{
protected:
int i;
public:
c(int ii=0):i(ii){}
virtual c *fun();
};
c* c::fun(){
cout<<"in c";
return &c();
}
class d : c
{
public:
d(){}
d* fun()
{
i = 9;
cout<<"in d"<<'\t'<<i;
return &d();
}
};
int main()
{
c *cc;
d dd;
cc = ⅆ
cc->fun();
}
It means that
is equivalent to
Your code is a
classextending astruct:is equivalent to
because
classhas private inheritance by default.And it means that all inherited and not overriden/overloaded/hidden methods from
care private ind.