Boost logo

Boost Users :

From: rz0 (rz0_at_[hidden])
Date: 2001-12-09 19:06:10


--- In Boost-Users_at_y..., Jon Kalb <kalb_at_L...> wrote:
> At 2:56 AM +0000 12/9/01, rz0 wrote:
> >#include <iostream>
> >#include <boost/smart_ptr.hpp>
> >
> >class A
> >{
> >public:
> > virtual void func1() { std::cout << "A::func1" << std::endl; }
> >};
> >
> >class B : public A
> >{
> >public:
> > void func1() { std::cout << "B::func1" << std::endl; }
> > void funcB() { std::cout << "B::funcB" << std::endl; }
> >};
> >
> >class C : public A
> >{
> >public:
> > void func1() { std::cout << "C::func1" << std::endl; }
> > void funcC() { std::cout << "C::funcB" << std::endl; }
> >};
> >
> >class Holder
> >{
> > boost::shared_ptr<A> aptr;
> >public:
> > void setclass(boost::shared_ptr<A> a) { aptr = a; }
> > void callfunc() { aptr->func1(); }
> >};
> >
> >int main()
> >{
> >
> > Holder holder;
> >
> > boost::shared_ptr<B> b(new B());
> > boost::shared_ptr<C> c(new C());
> >
> > holder.setclass(b); //<-------
> > holder.setclass(c); //<-------
> >
> > holder.callfunc();
> >
> >return 0;
> >}
> >
> >VC++ 6.0 flags the above lines with a conversion error.
> >
> >Is there any way to resolve this?
>
> Can you just define b and c as boost::shared_ptr<A>?

Hi Jon

Thank you very much for the response. Unfortunately this will cause
the same problem that I ran into with std::auto_ptr and that is
methods funcB and funcC which are exclusive to B and C are not
allowed to be called.

Take care
RZ


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