Mail Archives: djgpp/1997/05/30/23:20:42
In article <01bc6c06$d6e88ee0$1b2443a1 AT pcoec DOT uclm DOT es> "Roberto Henríquez Laurent" <shl24634 AT alumnos DOT inf-cr DOT uclm DOT es> writes:
>The trouble was that I had a class with overloaded constructors, and I was
>trying to call one of them from another, once in the caller I had some data
>in the format the called used. But I suppose I was doing it wrong so that
>the call to the constructor never happened. And the compiler didn't say
>anything. And the question is:
Calling a constructor while already in a constructor of the same class
is not an language error and hence the compiler should not complain.
However, it might be a logic error or some other error, hence you must
be careful it is really what you want to do. IOW, the ctor probably
did happen, but it's effect was that the _object it created_ went away
when the "outer" ctor returned so all you were left with was the original
object. That is, calling a ctor from a ctor brings about another object.
Often not was intended.
>If I have 2 constructors, e.g.: Class(int a, int b) and Class(String xyz),
>how should I call Class (int, int) after processing the String xyz in the
>other constructor?
It shouldn't do it. Sounds like what you want is a common third member
function (not a ctor), probably private, that both ctors call as appropriate.
- Greg
--
Comeau Computing, 91-34 120th Street, Richmond Hill, NY, 11418-3214
Producers of Comeau C++ 4.0 front-end pre-release
****WEB: http://www.comeaucomputing.com / Voice:718-945-0009 / Fax:718-441-2310
Here:comeau AT comeaucomputing DOT com / BIX:comeau or comeau AT bix DOT com / CIS:72331,3421
- Raw text -