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

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!charon.amdahl.com!pacbell.com!sgiblab!sdd.hp.com!ux1.cso.uiuc.edu!cs.uiuc.edu!sparc0b!pjl
  3. From: pjl@cs.uiuc.edu (Paul Lucas)
  4. Subject: Re: Is Ctor X() required for the object of class X to be able to be dynamically allocated?
  5. Message-ID: <BxxoyD.M2I@cs.uiuc.edu>
  6. Keywords: constructor X(), dynamic allocation
  7. Sender: news@cs.uiuc.edu
  8. Organization: University of Illinois at Urbana-Champaign
  9. References: <BxxC3p.Btn@math.uwaterloo.ca>
  10. Date: Wed, 18 Nov 1992 22:54:12 GMT
  11. Lines: 23
  12.  
  13. In <BxxC3p.Btn@math.uwaterloo.ca> xjzhu@math.uwaterloo.ca (Xiaojun Zhu) writes:
  14.  
  15. >Q: Is it necessary to have a constructor which took no argument in order
  16. >   for the object of a class to be able to be dynamically allocated?
  17.  
  18. >More specifically,  I have a class X, when I can say
  19.  
  20. >X *x=new X[10] ?
  21.  
  22. >Is it required that class X have a constructor X()?
  23.  
  24. >I had some experience with TC++(V1.00) which seems that X() is
  25. >required. Anybody has any experience? Why or why not such a ctor
  26. >is needed?
  27.  
  28.     Yes it is needed, but you don't have to define it unless you
  29.     define a different c'tor yourself; the compiler will generate
  30.     it for you unless you have const or reference data members or
  31.     your base class(es) does(do) not have a default c'tor(s).
  32. -- 
  33.     - Paul J. Lucas                University of Illinois    
  34.       AT&T Bell Laboratories        at Urbana-Champaign
  35.       Naperville, IL            pjl@cs.uiuc.edu
  36.