Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!samsung!crackers!jjmhome!zinn!nuucp From: mjv@objects.mv.com (Michael J. Vilot) Newsgroups: comp.lang.c++ Subject: Re: Copy constructors Message-ID: <1110@zinn.MV.COM> Date: 12 Jan 91 20:48:11 GMT Sender: nuucp@zinn.MV.COM Lines: 31 David Masterson asks about the effect of casting bits to create an object: > Assuming that type of the object is known after transmission, it > should be possible to cast the transmission buffer to that type and copy > construct a true object of that type using the buffer as input. It may indeed be possible, but as Joe Buck pointed out it may be neither portable nor guaranteed to work by any of the language's rules. The mechanics of virtual functions are clearly implementation-dependent (as they should be). Assuming you really want to pursue a design based on assembling bits in a buffer and not on using constructors to build up the objects, then you may be able to rely on the semantics of operator new. Specifically, the use of a ``placement expression.'' The number and type of arguments are up to you -- #include , declare the operator new() that you need, and you may be able to develop the kind of solution you are after. Rather than a cast, you would ``allocate'' a new object and provide arguments to operator new() and/or the class' constructor. You can then dereference the pointer thus obtained and treat the resulting object in the usual way. Obviously, this design approach is a bit tricky, and requires careful cooperation between operator new, the constructor(s), and the destructor for the class. But it's more portable than relying on the result of a cast. More importantly, it stays within the type system. Hope this helps, -- Mike Vilot, ObjectWare Inc, Nashua NH mjv@objects.mv.com (UUCP: ...!decvax!zinn!objects!mjv)