Boost logo

Boost Users :

From: dlux42 dlux_at_[hidden])
Date: 2003-02-11 05:13:44


--- In Boost-Users_at_[hidden], "Vaclav Vesely"
<vaclav.vesely_at_v...> wrote:
> Hi,
>
> in C++ it's possible to write this:
>
> class A {};
>
> class B: public A {};
>
> class X {
> virtual A* f() { ... };
> };
>
> class Y: public X {
> virtual B* f() { ... }; // B* is covariant from A*
> };
>
>
> However it is NOT possible to write that with shared_ptr:
>
> class X {
> shared_ptr<A> f() { ... };
> };
>
> class Y: public X {
> virtual shared_ptr<B> f() { ... }; // Error: shared_ptr<B> is NOT
> covariant from shared_ptr<A>
> };
>
>
> I don't know C++ standard very well (in fact I've never read it). So my
> question is: it's possible to adjust shared_ptr to allow such
constructions?

I'm also not a C++ guru, but I think it requires that shared_ptr<A> be
the parent of shared_ptr<B>. How it can be achieved?

If it could be possible in C++, it then it was easy:

template<typename T>
class shared_ptr<T>: public T* { ... }

but AFAIK it is not possible.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net