2012-01-20 21 views
-4

大学の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)))でコンパイルするためにVS2010の私のコピーに書かれたプログラムを取得しようとしています。
このプログラムは、自動タイプや移動コンストラクタなど、さまざまなC++ 11機能を使用します。
このすべてはVS2010に支障を働かないが、私は、Linux(g++ -g -Wall -std=c++0x -pedantic)でそれをコンパイルするとき、私はエラーの以下のスルーを取得:マップ/ Map.h以来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 

: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'のベクトルのベクトルをコピーできなかったことを伝えています。コードのどこかで見つけてください。あなたは 'Map :: Map(const Map&)'を何かのために必要としていますし、そのようなメンバを持っています... – jpalecek

+0

いくつかの(最小限の)コードを再現すれば、良い答えを得る可能性が高くなります。 MapNodeとMapWallを投稿できますか? 独自の移動コンストラクタがありますか? –

答えて

3

エラーメッセージからわかるように、vector<MapWall>を含むMapをコピーしようとしていますが、MapWallはコピーできません。

これらのタイプがコピー可能であると思われる場合は、コピーコンストラクタをMapWallに追加する必要があります。ユーザーが宣言した移動コンストラクタは、暗黙的に生成されないことを意味します。 (私は、VS2010が間違って1つを生成していると推測する危険があります;なぜあなたのコードがそこで動作するのかを説明するでしょう)。

それ以外の場合は、非公開のコピー済みコンストラクタをMapに追加すると、不正なコピー操作を追跡するのが簡単になる場合があります。コピーしようとしているものを正確に示すエラーメッセージが表示されます。

+0

'Map'はコピーコンストラクタを持っていないので正直に私には起こりませんでしたが、あなたは正しいです。関数の1つが参照の代わりに値で '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&&’ 

いくつかのコードを見ることなく、それは正確にあなたが何をしたか教えすることはできません。

関連する問題