You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This isn't really a bug report, so much as an FYI. static_cast<> doesn't work as expected when the type of the source pointer has more than one base with a virtual table. This causes CppObject::get() to return the wrong pointer when T has multiple base virtual tables.
I was able to work around the problem for my application (in VC++2013) with a few pretty simple modifications:
added a new objectPtr(void* class_id, bool is_const) overload to CppObject that calls objectPtr() by default;
implemented a helper template, Upcast, with a function void* get(Derived* d, void* other_id, bool is_const) that returns d when not specialized for a particular class, or that, when specialized, should search up the hierarchy from d for a base class with matching class_id;
changed calls to objectPtr() in CppObject methods into calls to objectPtr(class_id,is_const);
implemented an override of objectPtr(void*,bool) in CppObjectSharedPtr<SP,T> that uses Upcast::get() to search for the matching base class; and
implemented specializations of Upcast<> for my class hierarchy (used macros, but could also be done with C++11 for a class hierarchy having consistently-defined in-class typedef's of base and derived classes).
This did the trick for my current set of test cases. CppObjectPtr would need to be made into a template class, but otherwise it could be modified the same was as CppSharedObjectPtr. I am currently only using CppSharedObjectPtr (via boost::intrusive_ptr), so I did not make this modification.
Hope this can be of use to someone.
The text was updated successfully, but these errors were encountered:
This isn't really a bug report, so much as an FYI. static_cast<> doesn't work as expected when the type of the source pointer has more than one base with a virtual table. This causes CppObject::get() to return the wrong pointer when T has multiple base virtual tables.
I was able to work around the problem for my application (in VC++2013) with a few pretty simple modifications:
Here are snippets of the relevant changes:
This did the trick for my current set of test cases. CppObjectPtr would need to be made into a template class, but otherwise it could be modified the same was as CppSharedObjectPtr. I am currently only using CppSharedObjectPtr (via boost::intrusive_ptr), so I did not make this modification.
Hope this can be of use to someone.
The text was updated successfully, but these errors were encountered: