On Mon, 6 Sep 2010 16:27:56 +0200, Tang Jiang Jun
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