Hello,


class A
{
public:
A();
A(int a);
}

A::A() {
//how to instance the A(1) here
}

A::A(int a) {
cout << a;
}



As in the above code, how can I add a statement that can instance the A(int)
in the A() constructor ???

Eric


--
==========================
If you know what you are doing,
it is not called RESEARCH!
==========================

Re: How to call constructor in the constructor ??? by Carl

Carl
Fri Apr 23 00:26:27 CDT 2004

Eric Chow wrote:
> Hello,
>
>
> class A
> {
> public:
> A();
> A(int a);
> }
>
> A::A() {
> //how to instance the A(1) here
> }
>
> A::A(int a) {
> cout << a;
> }
>
>
>
> As in the above code, how can I add a statement that can instance the
> A(int) in the A() constructor ???

You cannot call one constructor from another in C++.

A couple of alternatives:

class A
{
public:
A(int a=1);
};

class A
{
void Init(int a);

public:
A()
{
Init(1);
}

A(int a)
{
Init(a);
}
};

-cd