home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / cplus / 13394 < prev    next >
Encoding:
Text File  |  1992-09-08  |  1.4 KB  |  48 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!taumet!steve
  3. From: steve@taumet.com (Steve Clamage)
  4. Subject: Re: Creating arrays of a class object using default constructor
  5. Message-ID: <1992Sep8.164841.24948@taumet.com>
  6. Organization: TauMetric Corporation
  7. References: <Bu7L6G.7C8@csc.liv.ac.uk>
  8. Date: Tue, 8 Sep 1992 16:48:41 GMT
  9. Lines: 37
  10.  
  11. scsr91@csc.liv.ac.uk (Mr. J.A. Coyne) writes:
  12.  
  13. >class compound  {
  14. >   basic * array; // pointer to class basic
  15. >public:
  16. >   compound(); // class constructor function
  17. >};
  18.  
  19. >compound::compound()  { array = new basic[10]; }
  20.  
  21. >class basic {
  22. >    int * vector;
  23. >public:
  24. >      basic(int =5) ;
  25. >};
  26.  
  27. >basic::basic(int size)  { vector = new int[size]; }
  28.  
  29. >The error message I recieve is  : default arguments for constructor for array
  30. >of class basic(2005)
  31.  
  32. This is an area where the language has changed.  An array of objects
  33. with a constructor require the "default constructor".  It used to be
  34. that the "default constructor" was one which had no parameters, and a
  35. constructor with all parameters defaulted was not a substitute.  The
  36. newer language rule is that the "default constructor" is one which
  37. does not require arguments, meaning that your code is now legal.
  38.  
  39. The cfront 2.1 compiler followed the old rule.  A workaround is to
  40. make two constructors:
  41.  
  42.     basic()        { vector = new int[5]; }
  43.     basic(int size) { vector = new int[size]; }
  44. -- 
  45.  
  46. Steve Clamage, TauMetric Corp, steve@taumet.com
  47. Vice Chair, ANSI C++ Committee, X3J16
  48.