|
Boost Users : |
Subject: Re: [Boost-users] [any] Is it possible to support polymorphism in boost::any?
From: Richard Damon (Richard_at_[hidden])
Date: 2010-09-06 14:53:52
On Mon, 6 Sep 2010 17:49:41 +0200, Tang Jiang Jun
<tangjiangjun_at_[hidden]> wrote:
>I agree with you that void* just support polymorphism for single
>inheritance.
>However I think maybe it is possible to make boost::any to support full
>polymorphic behavior, because, for boost::any, there still has accurate type
>information when casting happens. With some tricks, maybe we can use
>dynamic_cast to help boost::any to cast the internal pointer to correct
>child class object.
>
>Thanks!
>Tang Jiang Jun
>
void* does NOT officially support polymorphism. If you look at the
standard you can cast from T* to void* to T* (with allowed variation
in const and volatile) but not from A* to void* to B*, even if there
is a inheritance relationship between A and B. It may work for many
platforms (for single inheritance), but officially it is Undefined
Behavior.
Richard Damon
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net