home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!bellahs!jjamison
- From: jjamison@bellahs.com (John Jamison RD AC)
- Subject: Re: Is Ctor X() required for the object of class X to be able to be dynamically allocated?
- Message-ID: <1992Nov20.175458.8803@bellahs.com>
- Keywords: constructor X(), dynamic allocation
- Organization: Bell Atlantic Healthcare Systems
- References: <BxxC3p.Btn@math.uwaterloo.ca> <1992Nov19.191043.18010@bellahs.com> <1992Nov20.080626.9582@netcom.com>
- Date: Fri, 20 Nov 1992 17:54:58 GMT
- Lines: 51
-
- In article <1992Nov20.080626.9582@netcom.com> ort@netcom.com (David Oertel) 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.
- >
- > This is wrong, the compiler should automatically generate the
- > default constructor as well as the copy constructor, the assignment
- > operator, and the address-of operators, if you don't explicitly
- > specify them.
- >
- > ort@netcom.com
-
- Then CenterLine's implementation of AT&T CFront is misbehaving by generating the following
- output:
- CC tst.cc:
- "tst.cc", line 10: error: array of class foo that does not have a constructor taking no arguments
- 1 error
-
- on the following input:
- gaia:$ more tst.cc
- class foo {
- public:
- foo (int j) {i=j;};
- private:
- int i;
- };
-
- main()
- {
- foo * fooarr = new foo [30];
- }
-
- >--
-
-
- --
- /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
- John Jamison
- Bell Atlantic Healthcare Systems
- jjamison@bellahs.com
-