Newsgroups: comp.lang.c++ Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!think.com!snorkelwacker.mit.edu!bloom-picayune.mit.edu!ahodgson From: ahodgson@athena.mit.edu (Antony Hodgson) Subject: How do you copy a Derived object? Message-ID: <1991Mar26.152847.5853@athena.mit.edu> Sender: news@athena.mit.edu (News system) Organization: Massachusetts Institute of Technology Date: Tue, 26 Mar 91 15:28:47 GMT Lines: 20 Suppose I have a function, void f( Base& b ), and inside f() I want to make a local copy of whatever b is. Since b could actually be a derived class, I can't simply do the following: void f( Base& b ) { Base B(b); ... } nor can I do void f( Base& b ) { Base* B = new Base( b ); ... } What I really need to do is something like Base* B = new (typeof(b))(b). Is this possible? Thanks in advance for any help. Email replies are fine. Tony Hodgson ahodgson@hstbme.mit.edu