Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!iuvax!rutgers!dptg!ulysses!andante!alice!ark From: ark@alice.UUCP (Andrew Koenig) Newsgroups: comp.lang.c++ Subject: Re: copy objects to another location Message-ID: <9885@alice.UUCP> Date: 11 Sep 89 12:21:37 GMT References: <14265@polyslo.CalPoly.EDU> Distribution: usa Organization: AT&T Bell Laboratories, Liberty Corner NJ Lines: 26 In article <14265@polyslo.CalPoly.EDU>, ttwang@polyslo.CalPoly.EDU (Thomas Wang) writes: > There does not appear to be a portable way to copy an object from one > memory location to another. The operator '=' might be overloaded, so > I cannot depend on it for copying. Copying an object to a new location presumably means creating a new object that is a copy of the old one and then deleting the old object. To copy an object of class T, use T(const T&); if that doesn't work, nothing will. To determine the locations and handle the memory management, use the memory management stuff in cfront 2.0. For example, if `oldloc' and `newloc' point at the old and new locations, you want to write something like this: void* operator new(size_t, void* p) { return p; } new(newloc) T (*oldloc); oldloc->T::~T(); Now newloc points at a copy of the object and oldloc points at garbage that should be freed. None of this works, of course, if the old and new objects overlap. -- --Andrew Koenig ark@europa.att.com