Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!elroy.jpl.nasa.gov!jpl-devvax!seq From: seq@jpl-devvax.jpl.nasa.gov (Sequence Folks) Newsgroups: comp.lang.c++ Subject: The "new" Operator and the Copy Constructor Message-ID: <1991Mar27.233549.1487@jpl-devvax.jpl.nasa.gov> Date: 27 Mar 91 23:35:49 GMT Reply-To: russb@sampson.JPL.NASA.GOV (Russ Brill) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 57 In spite of a previous confidence in my understanding of the copy constructor, and with the ARM by my side, the following has me baffled: 1) The compiler complains when I try to create an object from the heap using the default copy constructor. class D {}; D d; D* pd; pd = new D(d); 2) The compiler complains when I try to create an object from the heap using the default copy constructor of a derived class when there is no default copy constructor for the base class. class B {}; class D : public B {}; D d; D* pd; pd = new D(d); 3) But everything works great if the base class has an explicity defined copy constructor! class B { public: B() {} B(B&) {} }; class D : public B {}; D d; D* pd; pd = new D(d); 4) And considering case #1, how come the *following* works?! class B { public: virtual B* copy() {return new B(*this);} }; This is all done on Sun cfront 2.0. I would appreciate an explanation (and, if possible, an ARM reference).