home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / cplus / 16653 < prev    next >
Encoding:
Text File  |  1992-11-20  |  1.8 KB  |  63 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!bellahs!jjamison
  3. From: jjamison@bellahs.com (John Jamison RD AC)
  4. Subject: Re: Is Ctor X() required for the object of class X to be able to be dynamically allocated?
  5. Message-ID: <1992Nov20.175458.8803@bellahs.com>
  6. Keywords: constructor X(), dynamic allocation
  7. Organization: Bell Atlantic Healthcare Systems
  8. References: <BxxC3p.Btn@math.uwaterloo.ca> <1992Nov19.191043.18010@bellahs.com> <1992Nov20.080626.9582@netcom.com>
  9. Date: Fri, 20 Nov 1992 17:54:58 GMT
  10. Lines: 51
  11.  
  12. In article <1992Nov20.080626.9582@netcom.com> ort@netcom.com (David Oertel) writes:
  13. >
  14. >
  15. >>>In article <BxxC3p.Btn@math.uwaterloo.ca> xjzhu@math.uwaterloo.ca (Xiaojun Zhu) writes:
  16. >>>Q: Is it necessary to have a constructor which took no argument in order
  17. >>>   for the object of a class to be able to be dynamically allocated?
  18. >>>
  19. >>>More specifically,  I have a class X, when I can say
  20. >>>
  21. >>>X *x=new X[10] ?
  22. >>>
  23. >>>Is it required that class X have a constructor X()?
  24. >>>
  25. >>I can't cite chapter and verse, but such a constructor is required to
  26. >>create arrays of objects.
  27. >
  28. >    This is wrong, the compiler should automatically generate the 
  29. >    default constructor as well as the copy constructor, the assignment
  30. >    operator, and the address-of operators, if you don't explicitly
  31. >    specify them.
  32. >
  33. >    ort@netcom.com
  34.  
  35. Then CenterLine's implementation of AT&T CFront is misbehaving by generating the following
  36. output:
  37. CC  tst.cc:
  38. "tst.cc", line 10: error: array of class foo that does not have a constructor taking no arguments
  39. 1 error
  40.  
  41. on the following input:
  42. gaia:$ more tst.cc
  43. class foo {
  44.     public:
  45.        foo (int j) {i=j;};
  46.    private:
  47.        int i;
  48. };
  49.  
  50. main()
  51. {
  52.     foo * fooarr = new foo [30];
  53. }
  54.  
  55. >-- 
  56.  
  57.  
  58. -- 
  59. /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  60. John Jamison
  61. Bell Atlantic Healthcare Systems
  62. jjamison@bellahs.com
  63.