Constructor questions

T

Tim Frink

Hi,

I've two questions on constructors:

1) Is the order in which class member are initialized
within the constructor crucial? So, do I have to preserve
the order in which class member have been declared in the header
file also for the constructor initializations?

2) Must STL containers like "list<ClassA*> mList" which I
declare in the header file be also initialized in the
constructor?

Regards,
Tim
 
P

peter koch

Hi,

I've two questions on constructors:

1) Is the order in which class member are initialized
within the constructor crucial? So, do I have to preserve
the order in which class member have been declared in the header
file also for the constructor initializations?

The order of initialisation will be in order of declaration (with base-
classes initialised first from left to right unless the base-class is
virtual). The order is therefore determined by the declaration and
good code would always follow that order.
2) Must STL containers like "list<ClassA*> mList" which I
declare in the header file be also initialized in the
constructor?

Yes, but it always will be. If you say nothing explicitly about mList
in the initialiser list, mLists default constructor will be called
(creating an empty list), just as for any other member or base-class.

/Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top