我試圖在我的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 ++下。
這是編譯器的一些怪癖,還是我做錯了什麼?
「在水晶球戰鬥中沒有規則。」 「不,那裏*是*一個規則:帶上一個水晶球。」 –
這不能由您發佈的行引起('walls.push_back ...')。編譯器告訴你它沒有複製'MapNodes'的矢量向量。在代碼中找到它。 MAYBE你需要'Map :: Map(const Map&)'來獲得一些東西,並且它有這樣的成員...... – jpalecek
如果你發佈了一些(最小的?)代碼,那麼你很可能會得到一個很好的答案。你可以發佈MapNode和MapWall嗎? 你有你自己的移動構造函數嗎? –