Boost logo

Boost Users :

From: Jon Kalb (kalb_at_[hidden])
Date: 2001-12-09 20:50:46


At 12:06 AM +0000 12/10/01, rz0 wrote:
>--- 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.

Your original code worked for me, but I'm using CodeWarrior. I
noticed that the function that you want to have called:

      template<typename Y> shared_ptr(const shared_ptr<Y>&);

is #ifdef'ed on BOOST_MSVC6_MEMBER_TEMPLATES, but I don't know what
that define means.

--
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