Boost logo

Boost :

From: Miki Jovanovic (miki_at_[hidden])
Date: 2000-02-08 10:14:45


"kevlin henney" <kevlin.henne-_at_[hidden]> wrote:
> What neither built-in pointers nor shared_ptr support is the ability
to
> treat a reference to a pointer to derived as a reference to a pointer
to
> base, which is what you are proposing. The reason this undesirable is
> because it is not type safe. Consider the consequences of allowing the
> following code to compile:
>
> shared_ptr<derived> p;
> shared_ptr<base> q(new base);
> shared_ptr<base> & r = p;
> r = q;

Haha, I knew there had to be something wrong with my idea... While this
is exactly what I wanted, I always thought only about const references,
therefore ignoring the problem of static (vs. virtual) assignment. A
simple alteration consisting of changing static_cast to a dynamic_cast
in the ptr() would solve this problem, but it is there that my
performance flew out of the window...

OK, this brings me to my basic question... We all use 'const
shared_ptr<class>&' as the parameter to methods for performance
reasons. How do you pass parameters around, when you have several
shared_ptr specialisations storing various classes in the hierarchy?

Cheers,

Miki Jovanovic.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk