Thanks Ion for the clarification and workaround.


On May 28, 2017, at 4:02 PM, Ion Gaztañaga via Boost-users <boost-users@lists.boost.org> 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@lists.boost.org
https://lists.boost.org/mailman/listinfo.cgi/boost-users