Topic: Operator new and multiple inheritance
Author: Pete Becker <petebecker@acm.org>
Date: 1998/07/18 Raw View
Hans Aberg wrote:
>
> If a class D is derived from both classes B1 and B2 (but none the latter
> classes are not derived from the other), and the latter have their own
> local "Bj::operator new", j = 1, 2, defined, how does the memory
> allocation of D take place?
>
> Does D use "B1::operator new" for the B1 part and "B2::operator new" for
> the B2 part, as one would expect?
No. It's ambiguous, just like the use of any other name that's defined
in more than one base class. C++ does not support allocating different
bases in different places.
--
Pete Becker
Dinkumware, Ltd.
http://www.dinkumware.com
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "Paul D. DeRocco" <pderocco@ix.netcom.com>
Date: 1998/07/18 Raw View
Hans Aberg wrote:
>
> If a class D is derived from both classes B1 and B2, and the latter
> have their own local "Bj::operator new", j = 1, 2, defined, how does
> the memory
> allocation of D take place?
>
> Does D use "B1::operator new" for the B1 part and "B2::operator new"
> for the B2 part, as one would expect?
A single call to operator new (either global or class-specific)
allocates a single chunk of memory. A single object necessarily resides
in a single chunk of memory. Therefore, the object of class D must
reside in a single chunk of memory returned by a single operator new
invocation.
In your example, the compiler will complain about an ambiguity in the
definition of operator new, just as it would if some other function had
been defined in multiple bases with the same name. The only "functions"
that are expected to be defined in multiple bases, and all automatically
called, are constructors and destructors.
--
Ciao,
Paul
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: haberg@REMOVE.matematik.su.se (Hans Aberg)
Date: 1998/07/17 Raw View
If a class D is derived from both classes B1 and B2 (but none the latter
classes are not derived from the other), and the latter have their own
local "Bj::operator new", j = 1, 2, defined, how does the memory
allocation of D take place?
Does D use "B1::operator new" for the B1 part and "B2::operator new" for
the B2 part, as one would expect?
Hans Aberg * Anti-spam: Remove "REMOVE." from email address.
* Email: Hans Aberg <mailto:haberg@member.ams.org>
* Home Page: <http://www.matematik.su.se/~haberg/>
* AMS member listing: <http://www.ams.org/cml/>
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]