Boost logo

Boost Users :

Subject: Re: [Boost-users] [Move] unique_ptr with boost vector container (C++98)
From: Gene Kang (gene.kang_at_[hidden])
Date: 2017-05-29 06:03:11


Thanks Ion for the clarification and workaround.

> On May 28, 2017, at 4:02 PM, Ion Gaztañaga via Boost-users <boost-users_at_[hidden]> wrote:
>
> On 27/05/2017 21:43, Gene Kang via Boost-users wrote:
>>
>> I’m using boost::movelib::unique_ptr with a polymorphic container of
>> type boost::container::vector and getting a compiler error that I
>> can’t seem to figure out (see code sample and attached compiler
>> output). Note, this error occurs when compiling without C++11
>> support w/ x86-64 gcc 4.9.3. When compiling w/ C++11 support (e.g.
>> -std=c++11) the code compiles fine. Any ideas ? Thanks in advance
>> for any help on this.
>
> Move emulation in C++98 does not support automatic conversions from derived to base classes.
>
> Try converting to FooAPtr first:
>
> #include <boost/move/unique_ptr.hpp>
> #include <boost/container/vector.hpp>
>
> class FooA
> {
> public:
> FooA() {}
>
> virtual ~FooA() {}
>
> virtual void execute() {}
> };
>
> class FooB : public FooA
> {
> public:
> FooB() {}
>
> virtual void execute() {}
> };
>
> int main()
> {
> typedef boost::movelib::unique_ptr<FooA> FooAPtr;
> typedef boost::movelib::unique_ptr<FooB> FooBPtr;
>
> boost::container::vector<FooAPtr> fooVector;
>
> FooBPtr fooBPtr(new FooB);
> FooAPtr fooAPtr(boost::move(fooBPtr));
>
> fooVector.push_back(boost::move(fooAPtr));
>
> return 0;
> }
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden] <mailto:Boost-users_at_[hidden]>
> https://lists.boost.org/mailman/listinfo.cgi/boost-users <https://lists.boost.org/mailman/listinfo.cgi/boost-users>



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