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