2017-05-16 3 views
1

Je suis en train de mettre en œuvre le constructeur de déplacement à l'extérieur du corps de la classe, mais il ne compilera pas correctementboost mouvement compilation erreur

#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) { } 

Je compilé ce code avec g ++, version mon g ++ est 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() 
+0

Semble compiler correctement dans MSVC 2013 – Tas

+0

Échec de g ++ 5.4.0 – flyzero

Répondre

0

Il a également échoué avec g ++ 5.4.0 - flyzero

Mu sois ta version boost.

Cela fonctionne très bien avec g ++ 5.4.1 et Boost 1.64. Si ce n'est pas le cas, vérifiez la sortie du préprocesseur pour toute erreur d'inclusion/macro.

0

Dans Linux, :: boost :: rv est déclarée avec l'attribut may_alias. Mon code compile correctement après avoir supprimé l'attribut may_alias.

#define BOOST_MOVE_ATTRIBUTE_MAY_ALIAS __attribute__((__may_alias__)) 

template <class T> 
class rv 
    : public ::boost::move_detail::if_c 
     < ::boost::move_detail::is_class<T>::value 
     , T 
     , ::boost::move_detail::nat 
     >::type 
{ 
    rv(); 
    ~rv() throw(); 
    rv(rv const&); 
    void operator=(rv const&); 
} BOOST_MOVE_ATTRIBUTE_MAY_ALIAS;