Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > constructor and initializer

Reply
Thread Tools

constructor and initializer

 
 
Vincent RICHOMME
Guest
Posts: n/a
 
      01-14-2006
Hi,

Let' say I have a class with an object pointer as member something like:

// classA.h
class A
{
A(B* pB);
B* m_pB;
};

//classA.cpp

class A:A(B* pB):
m_pB(NULL)
{
m_pB = pB;
if (m_pB == NULL)
return;
}

so I want to be sure m_pB is not NULL, so I am initializing it in
initialization list with NULL and after I am checking its value.
But my question is what is done first, the initialization(m_pB=NULL) or
the declaration in the body ?
 
Reply With Quote
 
 
 
 
TB
Guest
Posts: n/a
 
      01-14-2006
Vincent RICHOMME sade:
> Hi,
>
> Let' say I have a class with an object pointer as member something like:
>
> // classA.h
> class A
> {
> A(B* pB);
> B* m_pB;
> };
>
> //classA.cpp
>
> class A:A(B* pB):


A::A(B* pB):

> m_pB(NULL)
> {
> m_pB = pB;
> if (m_pB == NULL)
> return;
> }
>
> so I want to be sure m_pB is not NULL, so I am initializing it in
> initialization list with NULL and after I am checking its value.
> But my question is what is done first, the initialization(m_pB=NULL) or
> the declaration in the body ?


The constructor initializer list is executed before the constructor body.

TB
 
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
order of object initialization and the use of constructor initializer Jess C++ 8 04-28-2007 10:32 AM
Initializer vs. Constructor assignment Matthias Kaeppler Java 4 05-08-2005 06:56 AM
static initializer vs constructor Ed Thompson Java 9 10-11-2004 10:27 AM
No constructor initializer list in Java ? Razvan Java 7 07-04-2004 02:28 AM



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