Boost logo

Boost :

From: Valentin Bonnard (Bonnard.V_at_[hidden])
Date: 2000-03-16 10:21:50


ronenh_at_[hidden] wrote:

> How can I pass APtr object to method that get ConstAPtr.

Just do it.

> How can I use Polymorphism with smart pointer.

It should work.

> class A {
> :
> virtual void DoIt();
> :
> };
> typedef shared_ptr<A> APtr;
> typedef shaerd_ptr<const A> ConstAPtr;
>
> class Drive : public A{
> :
> virtual void DoIt();
> :
> };
> typedef shared_ptr<Drive> DrivePtr;

> void main()
  ^^^^
Hum hum

> Drive d;

> DrivePtr pD(&d);
                 ^^
Hum hum

The following should compile:

$ cat smart-ptr-const.cc
#include "smart_ptr.h"

using namespace boost;

typedef shared_ptr<A> APtr;
typedef shared_ptr<const A> ConstAPtr;

void func (ConstAPtr) {}

int main ()
{
  APtr p;
  func (p);
}

(I get an ICE, but should not.)

Anyway, the conversions won't work if your compiler
doesn't support template member function.

-- 
Valentin Bonnard

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