Connecting Tech Pros Worldwide Forums | Help | Site Map

call null constructor from another constructor

Matt Graham
Guest
 
Posts: n/a
#1: Jul 22 '05
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

Victor Bazarov
Guest
 
Posts: n/a
#2: Jul 22 '05

re: call null constructor from another constructor


"Matt Graham" <mdg149@optonline.net> wrote...[color=blue]
> Here's a subset of a class I'm trying to initialize:
> [...][/color]

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.


E. Robert Tisdale
Guest
 
Posts: n/a
#3: Jul 22 '05

re: call null constructor from another constructor


Matt Graham wrote:
[color=blue]
> Here's a subset of a class I'm trying to initialize:
>
> class uiForm {[/color]
private:[color=blue]
> 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.[/color]

No.

Matt Graham
Guest
 
Posts: n/a
#4: Jul 22 '05

re: call null constructor from another constructor


Victor Bazarov wrote:[color=blue]
> "Matt Graham" <mdg149@optonline.net> wrote...
>[color=green]
>>Here's a subset of a class I'm trying to initialize:
>>[...][/color]
>
>
> 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.[/color]

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
Closed Thread