home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!munnari.oz.au!jabaru.cec.edu.au!csource!david
- From: david@csource.oz.au (david nugent)
- Newsgroups: comp.lang.c++
- Subject: Default constructors
- Message-ID: <11RDwB1w165w@csource.oz.au>
- Date: Tue, 10 Nov 92 12:27:47 +1100
- Reply-To: david@csource.oz.au
- Organization: Unique Computing Pty Ltd, Melbourne, Australia
- Lines: 48
-
- I've stumbled on an annoying difference in C++ implementations in the
- generation of default constructors and copy constructors. In particular,
- gcc seems to have problems when an explicit call is made to a default
- constructor, whereas other compilers I use have no problem with this.
- On reading through ARM, I can't determine which is the 'correct'
- behaviour, so any comments would be welcome.
-
- Here's some code which demonstrates the problem:
-
- class X
- {
- int member1;
- char member2[2];
- };
-
- class Y : public X
- {
-
- public:
- Y () : X () {}
- Y (const X& a) : X (a) {}
- };
-
- gcc (2.2.2) won't compile this. Several other compilers I use have
- no problems. I also note that gcc has no problems initialising the
- basic built-in types with constructor syntax (eg. int x(1);) yet it
- still has problems explicitly calling the default constructor/copy
- constructor for class X as above. But it does 'call' the generated
- functions implicitly as required.
-
- It is annoying because it is often quite convenient to derive classes
- from existing structures defined in C header files, making use of
- the ability to attach additional data and functionality, and yet use
- those same objects with C library calls (eg. formating information
- on 'struct tm' etc.); and in cases where the above syntax is accepted,
- using a simple assignment in the derived class' constructure is
- inefficient because it causes the default constructor or copy
- constructor to be called twice.
-
- Responses by email please - I'll summarise to the group if there is
- any interest.
-
-
-
- Smoke me a kipper, Skipper - I'll be back for breakfast! - "Ace" Rimmer
- david@csource.oz.au 3:632/348@fidonet 58:4100/1@intlnet 199:4242/5@rainbownet
- Unique Computing P/L / Communications+LAN Specialists / Public Access USENET
- PO Box 352, Doveton, VIC, Aust 3144. Data/BBS: +61-3-792-3507 / +61-3-794-7949
-