From: comeau AT panix DOT com (Greg Comeau) Newsgroups: comp.os.linux.development.apps,comp.os.msdos.djgpp,comp.unix.programmer Subject: Re: C++ Passing ostreams by reference to methods, problem Date: 30 May 1997 15:20:03 -0400 Organization: Comeau Computing; http://www.comeaucomputing.com Lines: 29 Message-ID: <5mn993$n84@panix.com> References: <01bc6b49$27fce100$1b2443a1 AT pcoec DOT uclm DOT es> <01bc6c06$d6e88ee0$1b2443a1 AT pcoec DOT uclm DOT es> Reply-To: comeau AT comeaucomputing DOT com NNTP-Posting-Host: panix.com To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk In article <01bc6c06$d6e88ee0$1b2443a1 AT pcoec DOT uclm DOT es> "Roberto Henríquez Laurent" 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