• Advertisement
Sign in to follow this  

Class constructor and member constructors

This topic is 1930 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi

I have a class obejct "B" as a member variable within another class "A". Which constructor runs first, A or B?

The idea is that I need to init object B by passing down some information from A. I will leave the constructor of B blank and just call "B->init(pData)" from A's constructor.

Cheers

Share this post


Link to post
Share on other sites
Advertisement
B's constructor is run as part of A's constructor. As part of A's construction all base classes are constructed first, then all member variables in order of declaration and then the body of A's constructor is entered.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement