C++ C++;使用已删除函数std::unique_ptr和基类

C++ C++;使用已删除函数std::unique_ptr和基类,c++,c++11,boost,unique-ptr,C++,C++11,Boost,Unique Ptr,我有一个向量或游戏对象。我必须为c++11编译 std::vector< std::unique_ptr<Game> > games_; 派生类只实现validate()方法 现在,我的经理类想在线程池中发布一个“游戏”。这样做: void Manager::playGames() { boost::asio::io_service ioService; std::unique_ptr<boost::asio::io_serv

我有一个向量或游戏对象。我必须为c++11编译

std::vector< std::unique_ptr<Game> > games_;
派生类只实现validate()方法

现在,我的经理类想在线程池中发布一个“游戏”。这样做:

void Manager::playGames() {


        boost::asio::io_service ioService;

        std::unique_ptr<boost::asio::io_service::work> work( new boost::asio::io_service::work(ioService));

        boost::thread_group threadpool; //pool
        std::cout << "will start for " << playthreads_ << " threads and " << getTotalRequests() << "total requests\n";
        for (std::size_t i = 0; i < playthreads_; ++i)
                threadpool.create_thread(boost::bind(&boost::asio::io_service::run, &ioService));

        for ( std::size_t i=0; i < w_.size(); i++) {

                ioService.post(boost::bind(&Game::play, games_[i], 2));

        }    

        work.reset();
        threadpool.join_all();
        ioService.stop();

}
void管理器::playGames(){
boost::asio::io_服务ioService;
std::unique_ptr工作(新的boost::asio::io_服务::工作(ioService));
boost::thread\u组threadpool;//池
std::cout对于
boost::bind(&Game::play,games[i],2)
games[i]
被复制到bind,但是
std::unique\u ptr
不能被复制。(它只能被移动,但我认为在这里移动它不符合要求。)

您可以使用
boost::ref
避免复制,例如

ioService.post(boost::bind(&Game::play, boost::ref(games_[i]), 2));

您正在以某种方式请求一个唯一的\u ptr的副本,该副本已被删除,因为它们被定义为仅移动。错误:对使用boost编译的“get\u pointer(std::reference\u wrapper&)”的调用没有匹配的函数:ref@cateof对不起,我不能用boost测试它,我想你是对的。顺便说一句,用
std::ref
测试std::bind
也可以。
/home/manager.cpp: In member function ‘void Manager::playGames()’:
/home//manager.cpp:65:74: error: use of deleted function
 ‘std::unique_ptr<_Tp, _Dp>::unique_ptr(const std::unique_ptr<_Tp, _Dp>&)
 [with _Tp = Game; _Dp = std::default_delete<Game>]’ 
 ioService.post(boost::bind(&Game::play, games_[i], 2));
                                                                          ^
In file included from /opt/5.2/include/c++/5.2.0/memory:81:0,
                 from /home/manager.hpp:5,
                 from /home/manager.cpp:1: /opt/5.2/include/c++/5.2.0/bits/unique_ptr.h:356:7: note: declared
here
       unique_ptr(const unique_ptr&) = delete;
ioService.post(boost::bind(&Game::play, boost::ref(games_[i]), 2));