2012-01-20 67 views
-4

我試圖在我的VS2010的主版本上編寫一個程序,以編譯Fedora的大學版本(Linux version 3.1.9-1.fc16.x86_64 ([email protected]) (gcc version 4.6.2 20111027 (Red Hat 4.6.2-1) (GCC)))。
該程序使用各種c + + 11功能,如自動類型和移動構造函數。
這一切工作在VS2010沒有問題,但是當我編譯它在Linux(g++ -g -Wall -std=c++0x -pedantic),我得到的錯誤以下轉換:在g ++下使用std :: vectors的移動語義

In file included from /usr/lib/gcc/x86_64-redhat-linux/4.6.2/../../../../include/c++/4.6.2/vector:63:0, 
       from src/OpenGL/Renderer.h:4, 
       from src/Wolfenstein3D2011.cpp:2: 
/usr/lib/gcc/x86_64-redhat-linux/4.6.2/../../../../include/c++/4.6.2/bits/stl_construct.h: In function ‘void std::_Construct(_T1*, _Args&& ...) [with _T1 = Wulf::MapWall, _Args = {const Wulf::MapWall&}]’: 
/usr/lib/gcc/x86_64-redhat-linux/4.6.2/../../../../include/c++/4.6.2/bits/stl_uninitialized.h:77:3: instantiated from ‘static _ForwardIterator std::__uninitialized_copy<_TrivialValueTypes>::__uninit_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = __gnu_cxx::__normal_iterator<const Wulf::MapWall*, std::vector<Wulf::MapWall> >, _ForwardIterator = Wulf::MapWall*, bool _TrivialValueTypes = false]’ 
/usr/lib/gcc/x86_64-redhat-linux/4.6.2/../../../../include/c++/4.6.2/bits/stl_uninitialized.h:119:41: instantiated from ‘_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = __gnu_cxx::__normal_iterator<const Wulf::MapWall*, std::vector<Wulf::MapWall> >, _ForwardIterator = Wulf::MapWall*]’ 
/usr/lib/gcc/x86_64-redhat-linux/4.6.2/../../../../include/c++/4.6.2/bits/stl_uninitialized.h:259:63: instantiated from ‘_ForwardIterator std::__uninitialized_copy_a(_InputIterator, _InputIterator, _ForwardIterator, std::allocator<_Tp>&) [with _InputIterator = __gnu_cxx::__normal_iterator<const Wulf::MapWall*, std::vector<Wulf::MapWall> >, _ForwardIterator = Wulf::MapWall*, _Tp = Wulf::MapWall]’ 
/usr/lib/gcc/x86_64-redhat-linux/4.6.2/../../../../include/c++/4.6.2/bits/stl_vector.h:280:9: instantiated from ‘std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&) [with _Tp = Wulf::MapWall, _Alloc = std::allocator<Wulf::MapWall>, std::vector<_Tp, _Alloc> = std::vector<Wulf::MapWall>]’ 
src/Map/Map.h:17:8: instantiated from here 
/usr/lib/gcc/x86_64-redhat-linux/4.6.2/../../../../include/c++/4.6.2/bits/stl_construct.h:76:7: error: no matching function for call to ‘Wulf::MapWall::MapWall(const Wulf::MapWall&)’ 
/usr/lib/gcc/x86_64-redhat-linux/4.6.2/../../../../include/c++/4.6.2/bits/stl_construct.h:76:7: note: candidates are: 
src/Map/MapWall.h:18:3: note: Wulf::MapWall::MapWall(Wulf::MapWall&&) 
src/Map/MapWall.h:18:3: note: no known conversion for argument 1 from ‘const Wulf::MapWall’ to ‘Wulf::MapWall&&’ 
src/Map/MapWall.h:12:3: note: Wulf::MapWall::MapWall(Wulf::Direction) 
src/Map/MapWall.h:12:3: note: no known conversion for argument 1 from ‘const Wulf::MapWall’ to ‘Wulf::Direction’ 
/usr/lib/gcc/x86_64-redhat-linux/4.6.2/../../../../include/c++/4.6.2/bits/stl_construct.h: In function ‘void std::_Construct(_T1*, _Args&& ...) [with _T1 = Wulf::MapNode, _Args = {const Wulf::MapNode&}]’: 
/usr/lib/gcc/x86_64-redhat-linux/4.6.2/../../../../include/c++/4.6.2/bits/stl_uninitialized.h:77:3: instantiated from ‘static _ForwardIterator std::__uninitialized_copy<_TrivialValueTypes>::__uninit_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = __gnu_cxx::__normal_iterator<const Wulf::MapNode*, std::vector<Wulf::MapNode> >, _ForwardIterator = Wulf::MapNode*, bool _TrivialValueTypes = false]’ 
/usr/lib/gcc/x86_64-redhat-linux/4.6.2/../../../../include/c++/4.6.2/bits/stl_uninitialized.h:119:41: instantiated from ‘_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = __gnu_cxx::__normal_iterator<const Wulf::MapNode*, std::vector<Wulf::MapNode> >, _ForwardIterator = Wulf::MapNode*]’ 
/usr/lib/gcc/x86_64-redhat-linux/4.6.2/../../../../include/c++/4.6.2/bits/stl_uninitialized.h:259:63: instantiated from ‘_ForwardIterator std::__uninitialized_copy_a(_InputIterator, _InputIterator, _ForwardIterator, std::allocator<_Tp>&) [with _InputIterator = __gnu_cxx::__normal_iterator<const Wulf::MapNode*, std::vector<Wulf::MapNode> >, _ForwardIterator = Wulf::MapNode*, _Tp = Wulf::MapNode]’ 
/usr/lib/gcc/x86_64-redhat-linux/4.6.2/../../../../include/c++/4.6.2/bits/stl_vector.h:280:9: instantiated from ‘std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&) [with _Tp = Wulf::MapNode, _Alloc = std::allocator<Wulf::MapNode>, std::vector<_Tp, _Alloc> = std::vector<Wulf::MapNode>]’ 
/usr/lib/gcc/x86_64-redhat-linux/4.6.2/../../../../include/c++/4.6.2/bits/stl_construct.h:76:7: instantiated from ‘void std::_Construct(_T1*, _Args&& ...) [with _T1 = std::vector<Wulf::MapNode>, _Args = {const std::vector<Wulf::MapNode>&}]’ 
/usr/lib/gcc/x86_64-redhat-linux/4.6.2/../../../../include/c++/4.6.2/bits/stl_uninitialized.h:77:3: instantiated from ‘static _ForwardIterator std::__uninitialized_copy<_TrivialValueTypes>::__uninit_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = __gnu_cxx::__normal_iterator<const std::vector<Wulf::MapNode>*, std::vector<std::vector<Wulf::MapNode> > >, _ForwardIterator = std::vector<Wulf::MapNode>*, bool _TrivialValueTypes = false]’ 
/usr/lib/gcc/x86_64-redhat-linux/4.6.2/../../../../include/c++/4.6.2/bits/stl_uninitialized.h:119:41: instantiated from ‘_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = __gnu_cxx::__normal_iterator<const std::vector<Wulf::MapNode>*, std::vector<std::vector<Wulf::MapNode> > >, _ForwardIterator = std::vector<Wulf::MapNode>*]’ 
/usr/lib/gcc/x86_64-redhat-linux/4.6.2/../../../../include/c++/4.6.2/bits/stl_uninitialized.h:259:63: instantiated from ‘_ForwardIterator std::__uninitialized_copy_a(_InputIterator, _InputIterator, _ForwardIterator, std::allocator<_Tp>&) [with _InputIterator = __gnu_cxx::__normal_iterator<const std::vector<Wulf::MapNode>*, std::vector<std::vector<Wulf::MapNode> > >, _ForwardIterator = std::vector<Wulf::MapNode>*, _Tp = std::vector<Wulf::MapNode>]’ 
/usr/lib/gcc/x86_64-redhat-linux/4.6.2/../../../../include/c++/4.6.2/bits/stl_vector.h:280:9: instantiated from ‘std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&) [with _Tp = std::vector<Wulf::MapNode>, _Alloc = std::allocator<std::vector<Wulf::MapNode> >, std::vector<_Tp, _Alloc> = std::vector<std::vector<Wulf::MapNode> >]’ 
src/Map/Map.h:17:8: instantiated from here 
/usr/lib/gcc/x86_64-redhat-linux/4.6.2/../../../../include/c++/4.6.2/bits/stl_construct.h:76:7: error: no matching function for call to ‘Wulf::MapNode::MapNode(const Wulf::MapNode&)’ 
/usr/lib/gcc/x86_64-redhat-linux/4.6.2/../../../../include/c++/4.6.2/bits/stl_construct.h:76:7: note: candidates are: 
src/Map/MapNode.h:15:3: note: Wulf::MapNode::MapNode(Wulf::MapNode&&) 
src/Map/MapNode.h:15:3: note: no known conversion for argument 1 from ‘const Wulf::MapNode’ to ‘Wulf::MapNode&&’ 
src/Map/MapNode.h:10:3: note: Wulf::MapNode::MapNode(Wulf::coord, Wulf::coord, Wulf::word, Wulf::word) 
src/Map/MapNode.h:10:3: note: candidate expects 4 arguments, 1 provided 
make: *** [obj/main.o] Error 1 

由於地圖/ Map.h:17是class Map {,我已經不知道是什麼原因造成的。
唯一的線,我可以想像的那麼造成這個在地圖/ Map.cpp並
nodes[x].push_back(MapNode(x - halfwidth, y - halfheight, map[i], objs[i]));

walls.push_back(MapWall(air ? DIRECTION_WEST : DIRECTION_EAST));
這兩個VS2010下這些做工精細,成功地移動臨時到載體,但明顯在g ++下。
這是編譯器的一些怪癖,還是我做錯了什麼?

+3

「在水晶球戰鬥中沒有規則。」 「不,那裏*是*一個規則:帶上一個水晶球。」 –

+0

這不能由您發佈的行引起('walls.push_back ...')。編譯器告訴你它沒有複製'MapNodes'的矢量向量。在代碼中找到它。 MAYBE你需要'Map :: Map(const Map&)'來獲得一些東西,並且它有這樣的成員...... – jpalecek

+0

如果你發佈了一些(最小的?)代碼,那麼你很可能會得到一個很好的答案。你可以發佈MapNode和MapWall嗎? 你有你自己的移動構造函數嗎? –

回答

3

據我可以告訴錯誤信息,你試圖複製一個Map,其中包含vector<MapWall>,這是因爲MapWall不可複製的失敗。

如果這些類型應該是可複製的,那麼你需要添加一個複製構造函數到MapWall;您的用戶聲明的移動構造函數意味着不會隱式生成。 (我可能會猜測VS2010不正確地生成一個,這將解釋爲什麼你的代碼在那裏工作)。否則,您可能會發現通過向Map添加專用的已刪除副本構造函數來跟蹤流氓副本操作會更容易 - 那麼您應該會收到一條錯誤消息,顯示您正在嘗試複製它的內容。

+0

這真的沒有發生在我身上,因爲'Map'沒有拷貝構造函數,但是你是對的。其中一個功能是通過值而不是引用傳遞「Map」。 –

1

看到這些消息,我相信這是你的錯,和VS2010太permisive

此:

src/Map/MapNode.h:15:3: note: Wulf::MapNode::MapNode(Wulf::MapNode&&) 
src/Map/MapNode.h:15:3: note: no known conversion for argument 1 from ‘const Wulf::MapNode’ to ‘Wulf::MapNode&&’ 
src/Map/MapNode.h:10:3: note: Wulf::MapNode::MapNode(Wulf::coord, Wulf::coord, Wulf::word, Wulf::word) 

意味着你試圖lreference對象傳遞給一個移動構造函數,或者真正的構造。

同樣的錯誤是未來:

no known conversion for argument 1 from ‘const Wulf::MapWall’ to ‘Wulf::MapWall&&’ 

沒有看到一些代碼,這是不可能的,告訴你究竟做了什麼。