calling overloaded constructor from constructor

M

Michael Wild

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
 
A

Alf P. Steinbach

* 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.
 
M

Michael Wild

Alf said:
* Michael Wild:

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top