Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Constructor questions

Reply
Thread Tools

Constructor questions

 
 
Tim Frink
Guest
Posts: n/a
 
      06-28-2008
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
 
Reply With Quote
 
 
 
 
peter koch
Guest
Posts: n/a
 
      06-28-2008
On 28 Jun., 13:27, Tim Frink <plfr...@yahoo.de> wrote:
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
A constructor calling another constructor (default constructor)? Generic Usenet Account C++ 10 11-28-2007 04:12 AM
Copy constructor hides default constructor Aire C++ 3 01-25-2004 05:47 PM
java like constructor calling constructor lallous C++ 5 01-23-2004 11:52 PM
calling a constructor within a constructor Brett Irving C++ 3 06-29-2003 10:43 AM
why it's not possible calling constructor from constructor? Giulio C++ 9 06-25-2003 03:56 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57