Boost logo

Boost Users :

Subject: Re: [Boost-users] [Move] unique_ptr with boost vector container (C++98)
From: Ion Gaztañaga (igaztanaga_at_[hidden])
Date: 2017-05-28 23:02:13


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