Topic: why not "functionalize" dynamic_cast ?
Author: superone@mail.ru (sahn0)
Date: Thu, 5 Jul 2001 17:17:48 GMT Raw View
When using smart pointers it may be necessarry to use some sort of
downcasting.
It would be great if one can write
smart_ptr<A> ptrA;
smart_ptr<B> ptrB=dynamic_cast<B>(ptrA);
[instead of smart_ptr<B> ptrB=my_weird_downcast_to<B>(ptrA)]
with the function
template <class To,class From>
smart_ptr<To> dynamic_cast(smart_ptr<From> & ptr);
being invoked.
Standard dynamic_cast may not be a function template, however, and it
would not be allowed to create
To * dynamic_cast(From * ) and To & dynamic_cast(From &)
But I feel gotchas here. Am I right ?
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]