|
Boost Users : |
From: Jon Kalb (kalb_at_[hidden])
Date: 2001-12-08 22:20:51
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>?
-- Jon Kalb Kalb_at_[hidden]
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