home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!spool.mu.edu!umn.edu!deci.cs.umn.edu!hansen
- From: hansen@deci.cs.umn.edu (David M. Hansen)
- Subject: Re: Is Ctor X() required for the object of class X to be able to be dynamically allocated?
- Message-ID: <1992Nov20.152131.181@news2.cis.umn.edu>
- Keywords: constructor X(), dynamic allocation
- Sender: news@news2.cis.umn.edu (Usenet News Administration)
- Nntp-Posting-Host: deci.cs.umn.edu
- Organization: University of Minnesota
- References: <BxxC3p.Btn@math.uwaterloo.ca> <1992Nov19.191043.18010@bellahs.com>
- Date: Fri, 20 Nov 1992 15:21:31 GMT
- Lines: 29
-
- In article <1992Nov19.191043.18010@bellahs.com>, jjamison@bellahs.com (John Jamison RD AC) writes:
- |> In article <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 can't cite chapter and verse, but such a constructor is required to
- |> create arrays of objects.
-
- From the ARM...
-
- Chapter: 5.3.3 (p 61)
- Verse: "Arrays of objects of a class with constructors can be created by
- operator new only if the class has a default constructor"
-
- and from 12.1, p 264: "A default constructor for a class X is a constructor
- of class X that can be called without an argument."
-
- Two points: A default constructor is needed only if your class already
- has constructors, and the default constructor need not take the form X::X(),
- but something along the lines of X::X(int i=0) is also acceptable, because
- that constructor may be called without an argument.
-
- -=Dave
-