#942 closed Feature Requests (None)
sort of dynamic_cast for smart pointers
Reported by: | nobody | Owned by: | nobody |
---|---|---|---|
Milestone: | Component: | None | |
Version: | None | Severity: | |
Keywords: | Cc: |
Description
would not it be cool to have such feature ? so i can write shared_ptr<A> pA=new B(); shared_ptr<B> pB=downcast<B>(pA);
Change History (2)
comment:2 by , 21 years ago
Logged In: NO >I'd need to see a more complete proposal before taking any >action on this one. You might want to post something on >the main list. Sorry, i don't know what 'main list' is, so i'll try to explain here. In two words, i want a function with signature template <class To,class From> smart_ptr<To> downcast(smart_ptr<From>) which will attempt to cast From* to To* (the way dynamic_cast doing this) and will return smart_ptr<To> sharing same reference count with smart_ptr<From> in case of success. If the cast is illegal, the function will return null-smart_ptr<To>. For me, such a function is very convenient and absolutely necessary in some cases.
Note:
See TracTickets
for help on using tickets.