home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!taumet!steve
- From: steve@taumet.com (Steve Clamage)
- Subject: Re: Creating arrays of a class object using default constructor
- Message-ID: <1992Sep8.164841.24948@taumet.com>
- Organization: TauMetric Corporation
- References: <Bu7L6G.7C8@csc.liv.ac.uk>
- Date: Tue, 8 Sep 1992 16:48:41 GMT
- Lines: 37
-
- scsr91@csc.liv.ac.uk (Mr. J.A. Coyne) writes:
-
- >class compound {
- > basic * array; // pointer to class basic
- >public:
- > compound(); // class constructor function
- >};
-
- >compound::compound() { array = new basic[10]; }
-
- >class basic {
- > int * vector;
- >public:
- > basic(int =5) ;
- >};
-
- >basic::basic(int size) { vector = new int[size]; }
-
- >The error message I recieve is : default arguments for constructor for array
- >of class basic(2005)
-
- This is an area where the language has changed. An array of objects
- with a constructor require the "default constructor". It used to be
- that the "default constructor" was one which had no parameters, and a
- constructor with all parameters defaulted was not a substitute. The
- newer language rule is that the "default constructor" is one which
- does not require arguments, meaning that your code is now legal.
-
- The cfront 2.1 compiler followed the old rule. A workaround is to
- make two constructors:
-
- basic() { vector = new int[5]; }
- basic(int size) { vector = new int[size]; }
- --
-
- Steve Clamage, TauMetric Corp, steve@taumet.com
- Vice Chair, ANSI C++ Committee, X3J16
-