Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2001-07-24 15:24:02

From: "Greg Colvin" <gcolvin_at_[hidden]>

> template<typename BasePtr, typename DerivedPtr>
> DerivedPtr whatever(BasePtr in) {
> ...
> DerivedPtr p = do_dynamic_cast<DerivedPtr>(in);
> ...
> return p;
> }

Or something like

template<class Ptr> void whatever(Ptr p)
   if(IDrawable q = do_dynamic_cast<IDrawable>(p)) q->draw();

where IDrawable is typedef'ed somewhere to be, say, shared_ptr<Drawable>.

(As an aside, people like to implement their own COM-like component systems;
it would be great if shared_ptr<> can be used for this. The two main
obstacles are (1) no 'queryInterface' support - this would hopefully be
addressed by do_dynamic_cast - and (2) a shared_ptr<> created in a DLL and
destroyed in the main program causes problems when different heaps are

Still, I prefer that shared_dynamic_cast<> be left as an option. More
focused (less generic) interfaces are less error prone, when genericity is
not required.

Peter Dimov
Multi Media Ltd.

Boost list run by bdawes at, gregod at, cpdaniel at, john at