By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,171 Members | 1,027 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,171 IT Pros & Developers. It's quick & easy.

calling overloaded constructor from constructor

P: n/a
hi everybody

i suppose this question has been answered a countless times, but i can't
seem to find the answer...

how do i call an overloaded version of a constructor from a constructor?
suppose something like this:

class A
{
int field;
A(int i){field = i;}
A()
{
// and here comes the guesswork:
A(1);
}
};

what i want to do is calling another constructor with default arguments.

thanks for any help and hints

- michael
Dec 7 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
* Michael Wild:

i suppose this question has been answered a countless times, but i can't
seem to find the answer...

how do i call an overloaded version of a constructor from a constructor?


Within the same class you can't.

You can introduce an artificial base class, use default values, or use
an init-function.

The latter is a FAQ.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Dec 7 '05 #2

P: n/a
Alf P. Steinbach wrote:
* Michael Wild:
i suppose this question has been answered a countless times, but i can't
seem to find the answer...

how do i call an overloaded version of a constructor from a constructor?


Within the same class you can't.

You can introduce an artificial base class, use default values, or use
an init-function.

The latter is a FAQ.


Thanks. I'll stick with the init function then.
Dec 7 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.