我试图在类主体之外实现 move 构造函数,但它无法正确编译
#include <boost/move/move.hpp>
class Test
{
BOOST_COPYABLE_AND_MOVABLE(Test)
public:
Test() {}
Test(const Test & other) { }
Test(BOOST_RV_REF(Test) other);
Test & operator=(BOOST_COPY_ASSIGN_REF(Test) other) { return *this; }
Test & operator=(BOOST_RV_REF(Test) other) { return *this; }
};
Test::Test(BOOST_RV_REF(Test) other) { }
这段代码是我用g++编译的,我的g++版本是4.4.7
$ g++ -c test.cpp
test.cpp:15: error: prototype for 'Test::Test(boost::rv<Test>&)' does not match any in class 'Test'
test.cpp:9: error: candidates are: Test::Test(boost:rv<Test>&)
test.cpp:8: error: Test::Test(const Test&)
test.cpp:7: error: Test::Test()
最佳答案
It also failed with g++ 5.4.0 – flyzero
必须是您的升级版本。
它适用于 g++ 5.4.1 和 Boost 1.64。如果不是,请检查预处理器输出是否有任何包含/宏错误。
关于c++ - boost move 编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43992462/