Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > call null constructor from another constructor

Reply
Thread Tools

call null constructor from another constructor

 
 
Matt Graham
Guest
Posts: n/a
 
      02-06-2004
Here's a subset of a class I'm trying to initialize:

class uiForm {
public:
uiForm();
uiForm( unsigned short );
unsigned short m_method;
unsigned short m_form_id;
FormType *m_frmP;
char *m_title;
};

I have this as my null constructor and the constructor below is passed
an integer to set one of the parameters. But I want the rest of the
data to be initialized the same as in the empty constructor. Now,
what I'm wondering is if there is a way I can have integer constructor
call the null constructor, and then I can initialize the one m_form_id
value explicitly.

uiForm::uiForm() :
m_method( 1 ),
m_form_id(),
m_frmP(),
m_title()
{
}

uiForm::uiForm( unsigned short frm_id ) : m_form_id( frm_id )
{
}

Thanks,
Matt
 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      02-06-2004
"Matt Graham" <> wrote...
> Here's a subset of a class I'm trying to initialize:
> [...]


Is this a write-only newsgroup? Less that a week ago
the influx of "how to call a constructor from another
constructor" messages began. Have you seen any of
them?

No matter. The subject is covered in the FAQ. Please
see Constructors section.


 
Reply With Quote
 
 
 
 
E. Robert Tisdale
Guest
Posts: n/a
 
      02-06-2004
Matt Graham wrote:

> Here's a subset of a class I'm trying to initialize:
>
> class uiForm {

private:
> unsigned short m_method;
> unsigned short m_form_id;
> FormType *m_frmP;
> char *m_title;
> public:
> uiForm(unsigned short);
> uiForm(void);
> };
>
> I have this
>
> uiForm::uiForm(): m_method(1),
> m_form_id(0), m_frmP(0), m_title(0) { }
>
> as my [default] constructor and the [explicit] constructor below
>
> uiForm::uiForm(unsigned short frm_id): m_method(1),
> m_form_id(frm_id), m_frmP(0), m_title(0) { }
>
> is passed an integer to set one of the parameters.
> But I want the rest of the data to be initialized
> the same as in the [default] constructor.
> Now, what I'm wondering is if there is a way
> I can have integer constructor call the [default] constructor
> and then I can initialize the one m_form_id value explicitly.


No.

 
Reply With Quote
 
Matt Graham
Guest
Posts: n/a
 
      02-07-2004
Victor Bazarov wrote:
> "Matt Graham" <> wrote...
>
>>Here's a subset of a class I'm trying to initialize:
>>[...]

>
>
> Is this a write-only newsgroup? Less that a week ago
> the influx of "how to call a constructor from another
> constructor" messages began. Have you seen any of
> them?
>
> No matter. The subject is covered in the FAQ. Please
> see Constructors section.


Yeah, I knew I was going to get it for this one
I found that thread only a few minutes after posting. I had done some
searching, but couldn't imagine that it would be right there in front of
me like that. I'll have to look through the FAQ a little more carefully
from now on. thanks
 
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
Does C++ allow a constructor to call another constructor of the sameclass? Warren Tang C++ 9 04-15-2008 01:03 PM
A constructor calling another constructor (default constructor)? Generic Usenet Account C++ 10 11-28-2007 04:12 AM
How to call a constructor from within another constructor Andy C++ 9 09-24-2006 03:17 PM
Cannot invoke Call with null namespace URI for method null raviupasi@gmail.com Java 0 05-12-2006 01:34 PM
"stringObj == null" vs "stringObj.equals(null)", for null check?? qazmlp1209@rediffmail.com Java 5 03-29-2006 10:37 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