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

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!spool.mu.edu!umn.edu!deci.cs.umn.edu!hansen
  3. From: hansen@deci.cs.umn.edu (David M. Hansen)
  4. Subject: Re: Is Ctor X() required for the object of class X to be able to be dynamically allocated?
  5. Message-ID: <1992Nov20.152131.181@news2.cis.umn.edu>
  6. Keywords: constructor X(), dynamic allocation
  7. Sender: news@news2.cis.umn.edu (Usenet News Administration)
  8. Nntp-Posting-Host: deci.cs.umn.edu
  9. Organization: University of Minnesota
  10. References: <BxxC3p.Btn@math.uwaterloo.ca> <1992Nov19.191043.18010@bellahs.com>
  11. Date: Fri, 20 Nov 1992 15:21:31 GMT
  12. Lines: 29
  13.  
  14. In article <1992Nov19.191043.18010@bellahs.com>, jjamison@bellahs.com (John Jamison RD AC) writes:
  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. From the ARM...
  29.  
  30. Chapter: 5.3.3 (p 61)
  31. Verse: "Arrays of objects of a class with constructors can be created by 
  32. operator new only if the class has a default constructor"
  33.  
  34. and from 12.1, p 264: "A default constructor for a class X is a constructor
  35. of class X that can be called without an argument."
  36.  
  37. Two points: A default constructor is needed only if your class already 
  38. has constructors, and the default constructor need not take the form X::X(),
  39. but something along the lines of X::X(int i=0) is also acceptable, because
  40. that constructor may be called without an argument.
  41.  
  42.                     -=Dave
  43.