Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!ucsd!ucbvax!bloom-beacon!eru!hagbard!sunic!mcsun!ukc!mrccrc!dcurtis From: dcurtis@crc.ac.uk (Dr. David Curtis) Newsgroups: comp.lang.c++ Subject: Re: Array of class objects Message-ID: <372@tin.crc.ac.uk> Date: 28 Nov 90 09:47:18 GMT References: <1756@enuxha.eas.asu.edu> <1990Nov15.050358.16043@clear.com> <1650@fornax.UUCP> Reply-To: dcurtis@crc.ac.uk (Dr. David Curtis) Organization: MRC Human Genome Resource Centre Lines: 32 In article mlm@cs.brown.edu writes: > >About the two constructors: > pnt::pnt( int x = 0, int y = 0, int y = 0 ) {}; > pnt::pnt() {}; >Under AT&T C++ 2.0, these were in fact two different constructors, and >in order to initialize an array of pnt's it was necessary to include >the second one. Under AT&T C++ 2.1, that restriction was lifted, and >the first constructor will be used to initialize arrays of pnt's, if >the second constructor is not supplied. Under either compiler, I >believe that including both versions of the constructor and then >defining a variable > pnt P; >will result in a compile-time error on that line, as the compiler will >be unable to disambiguate that call. > > Moises Easy to get round this, just take out the first default argument to the first constructor: pnt::pnt( int x, int y = 0, int z = 0 ) { pnt_x=x; pnt_y=y; pnt_z=z; } pnt::pnt() { pnt_x=0; pnt_y=0; pnt_z=0; } Dave Curtis Academic Department of Psychiatry, Janet: dc@UK.AC.UCL.SM.PSYCH Middlesex Hospital, Elsewhere: dc@PSYCH.SM.UCL.AC.UK Mortimer Street, London W1N 8AA. EARN/Bitnet: dc%PSYCH.SM.UCL@UKACRL Tel 081-380 9475 Fax 081-323 1459 Usenet: ...!mcsun!ukc!mrccrc!D.Curtis