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

On Mon, Sep 6, 2010 at 5:29 PM, Richard Damon <Richard@damon-family.org> wrote:
On Mon, 6 Sep 2010 16:27:56 +0200, Tang Jiang Jun
<tangjiangjun@gmail.com> wrote:

>Is it possible to make it support this polymorphism usage? Because
>boost::any is a type-safe replacement of void*, I hope that boost::any has
>the same polymorphic behavior as void*.
>
>Regards,
>Tang Jiang Jun


One thing to point out is that void* doesn't fully support polymorphic
behavior.

given:

class a {
public:
 int aa;
};

class b {
public:
 int bb;
}

class c: public a, public b {
 int cc;
} ccc;


int main() {
 void* ptr = &ccc;

 class a* ptr1 = (class a*)(ptr);
 class b* ptr2 = (class b*)(ptr);
}

My understanding is that the assignments to ptr1 and ptr2 are
undefined behavior, and that in practice the assignment to ptr2 will
normally be "wrong" in that ptr2 will not point to the b sub-object.

any will just tell you that you are "breaking the rules" while void
will not.


Richard Damon
_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users