473,396 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

call null constructor from another constructor

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
Jul 22 '05 #1
3 2052
"Matt Graham" <md****@optonline.net> 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.
Jul 22 '05 #2
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.

Jul 22 '05 #3
Victor Bazarov wrote:
"Matt Graham" <md****@optonline.net> 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
Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Dario | last post by:
This is a technical C++ post regarding the Microsoft runtime error R6025 Pure Virtual Function Call that sometime occurs in programs compiled with Microsoft Visual C++ 6.0. Please consider the...
3
by: S³awek | last post by:
Can one constructor of an object call another constructor of the same class? class foo { foo(float f, int i) // a "full" constructor { ... } foo(int i) // a "simplified" constructor {
7
by: Mark Miller | last post by:
I am using Reflection.Emit to dynamically build a class. A method of the class to be built requires a Parameter of type "Type". But I don't know how to use Emit to pass a call of "typeof()" to the...
26
by: Paul | last post by:
public class A { public A () { // here I would like to call the second version of _ctor, how to accomplish this ? } public A (int a, int b, int c) {
5
by: Martin Jørgensen | last post by:
Hello again, Sorry to bother but I guess my C++ book isn't very good since it obviously contains errors so the program code doesn't work with g++. However I don't understand what the problem...
18
by: cmk128 | last post by:
hi 1 #include <stdio.h> 2 3 class A{ 4 private: 5 int x; 6 public: 7 A(int x){ 8 this->x;
7
by: dragoncoder | last post by:
Hello experts, I have the following code me. =cat mystring.h #include<iostream> using namespace std; class mystring {
6
by: HolyShea | last post by:
All, Not sure if this is possible or not - I've created a class which performs an asynchronous operation and provides notification when the operation is complete. I'd like the notification to be...
12
by: Rahul | last post by:
Hi Everyone, I have the following code and i'm able to invoke the destructor explicitly but not the constructor. and i get a compile time error when i invoke the constructor, why is this so? ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.