constructor in inheritance

#include <iostream>
using namespace std;
class a
{
int b;
protected:
a()
{
cout<<"in a constructor";
}
};
class b:public a
{
int p;
};
int main()
{
b r;
return 0;
}
i just want to ask that why a::a() constructor is in protected mode then why is invoke?
When you are creating object, all constructors from most bese class to derived itself are executed in order.
yes i now my frnd but in a::a(); have access control is protected then how it can invoke ?
Constructors of base classes are invoked from derived class. And derived class can call protected members of base classes.
Last edited on
ok now i understand
this property can also follow in virtual function constructor ?
this property can also follow in virtual function constructor ?
What do you mean?
i mean to say when we use virtual function in a class then this property of calling base to drive constructor also follow that time ?
If you calling virtual function, then object is already constructed, unless you are calling virtual function from the constructor. Which is might not work as you expect.

Example of what you want to know would be good.
ok my frnd i understand this concept can you help me for other concept ?
can you help me for other concept ?
Which concept? Presence or absence of virtual function does not change how class is created.
ok thanks my friend
Topic archived. No new replies allowed.