Can someone explain to me the difference between:
shared_dynamic_cast and dynamic_pointer_cast from the Boost library?
It appears to me that they may be equivalent.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Given a
shared_ptr<T>, the two functions are indeed equivalent.The difference is that
shared_dynamic_castonly works withshared_ptr<>‘s, whiledynamic_pointer_castworks with any kind of pointer (via overloading). This enables you to perform a dynamic cast on any pointer concept, regardless of how that pointer is actually composed:Because
dynamic_pointer_casthas the capability ofshared_dynamic_castand more, the latter function is deprecated. (Likewise in C++11, there only existsdynamic_pointer_cast.)(The idea is the same for the other cast variants too, of course.)