-1

我得到类似的东西:

[jiewmeng@JM Assignment 2]$ mpic++ basketball-match.cpp -o basketball-match && mpirun -np 12 basketball-match
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../include/c++/4.7.2/vector:70:0,
                 from basketball-match.cpp:4:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/vector.tcc: In instantiation of ‘void std::vector<_Tp, _Alloc>::_M_insert_aux(std::vector<_Tp, _Alloc>::iterator, const _Tp&) [with _Tp = int [2]; _Alloc = std::allocator<int [2]>; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<int (*)[2], std::vector<int [2]> >; typename std::_Vector_base<_Tp, _Alloc>::pointer = int (*)[2]]’:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/stl_vector.h:893:4:   required from ‘void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = int [2]; _Alloc = std::allocator<int [2]>; std::vector<_Tp, _Alloc>::value_type = int [2]]’
basketball-match.cpp:145:49:   required from here
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/vector.tcc:327:19: error: array must be initialized with a brace-enclosed initializer
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/vector.tcc:333:4: error: invalid array assignment
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../include/c++/4.7.2/x86_64-unknown-linux-gnu/bits/c++allocator.h:34:0,
                 from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/allocator.h:48,
                 from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/stl_tree.h:64,
                 from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../include/c++/4.7.2/map:60,
                 from /usr/include/openmpi/ompi/mpi/cxx/mpicxx.h:38,
                 from /usr/include/mpi.h:2087,
                 from basketball-match.cpp:1:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../include/c++/4.7.2/ext/new_allocator.h: In instantiation of ‘void __gnu_cxx::new_allocator<_Tp>::construct(__gnu_cxx::new_allocator<_Tp>::pointer, const _Tp&) [with _Tp = int [2]; __gnu_cxx::new_allocator<_Tp>::pointer = int (*)[2]]’:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../include/c++/4.7.2/ext/alloc_traits.h:202:9:   required from ‘static void __gnu_cxx::__alloc_traits<_Alloc>::construct(_Alloc&, __gnu_cxx::__alloc_traits<_Alloc>::pointer, const _Tp&) [with _Tp = int [2]; _Alloc = std::allocator<int [2]>; __gnu_cxx::__alloc_traits<_Alloc>::pointer = int (*)[2]]’
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/stl_vector.h:885:6:   required from ‘void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = int [2]; _Alloc = std::allocator<int [2]>; std::vector<_Tp, _Alloc>::value_type = int [2]]’
basketball-match.cpp:145:49:   required from here
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../include/c++/4.7.2/ext/new_allocator.h:120:9: error: parenthesized initializer in array new [-fpermissive]

源代码可以在GitHub上找到。可能是什么原因?

4

1 回答 1

9

你的问题在这里

vector<int[2]> playersAtBall;

向量元素的类型必须是可复制构造的。数组不是。所以你不能有一个vector<int[2]>. 您可以将数组包装到可复制的结构中,或者std::pair<int, int>改用。

如果你有 C++11 编译器,你可以使用std::array<int,2>,正如 mfontanini 在评论中指出的那样。如果你没有,但愿意使用 boost,你可以使用boost::array<int, 2>

于 2012-11-13T14:34:48.543 回答