我有一个结构如下:
typedef struct
{
vector<int[6]> swaps;
int score;
}State;
Run Code Online (Sandbox Code Playgroud)
我随后即时通讯
State s1;
int s1arr[]={1,2,3,4,5,6};
s1.swaps.push_back(s1arr); //this is line number 164 in the error
s1.score=23;
Run Code Online (Sandbox Code Playgroud)
以下所有内容都是一个巨大的错误.我找不到除了位置之外的任何地方的类似错误(不在堆栈溢出的地方也没有应答).当我推回s1.swaps时会发生错误.如果有人能帮助我找出错误,我将感激不尽
错误日志
In file included from c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\vector:69:0,
from SessionOrganizer.h:13,
from SessionOrganizer.cpp:7:
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\vector.tcc: In instantiation of
'void std::vector<_Tp, _Alloc>::_M_insert_aux(std::vector<_Tp, _Alloc>::iterator
, const _Tp&) [with _Tp = int [6]; _Alloc = std::allocator<int [6]>; std::vector
<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<int (*)[6], std::vector<i
nt [6]> >; typename std::_Vector_base<_Tp, _Alloc>::pointer = int (*)[6]]':
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_vector.h:913:28: required
from 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = in
t [6]; _Alloc = std::allocator<int [6]>; std::vector<_Tp, _Alloc>::value_type =
int [6]]'
SessionOrganizer.cpp:164:33: required from here
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\vector.tcc:329:19: error: array
must be initialized with a brace-enclosed initializer
_Tp __x_copy = __x;
^
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\vector.tcc:335:16: error: invali
d array assignment
*__position = __x_copy;
^
In file included from c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\mingw32\bits\c+
+allocator.h:33:0,
from c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\allocator.
h:46,
from c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\string:41,
from SessionOrganizer.h:10,
from SessionOrganizer.cpp:7:
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\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 [6]; __gnu_cxx::new_allocator<_Tp>::point
er = int (*)[6]]':
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\ext\alloc_traits.h:216:9: required
from 'static void __gnu_cxx::__alloc_traits<_Alloc>::construct(_Alloc&, __gnu_cx
x::__alloc_traits<_Alloc>::pointer, const _Tp&) [with _Tp = int [6]; _Alloc = st
d::allocator<int [6]>; __gnu_cxx::__alloc_traits<_Alloc>::pointer = int (*)[6]]'
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_vector.h:906:34: required
from 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = in
t [6]; _Alloc = std::allocator<int [6]>; std::vector<_Tp, _Alloc>::value_type =
int [6]]'
SessionOrganizer.cpp:164:33: required from here
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\ext\new_allocator.h:130:9: error: par
enthesized initializer in array new [-fpermissive]
{ ::new((void *)__p) _Tp(__val); }
^
Makefile:2: recipe for target 'all' failed
Run Code Online (Sandbox Code Playgroud)
For*_*veR 10
你不应该存储C array
在矢量中,它既不可复制,也不可移动,也不可分配.如果可以使用C++ 11,则可以使用std :: array,否则可以使用boost::array
.你也可以使用std::vector<std::vector<int> >
.
vector<array<int, 6> > swaps;
Run Code Online (Sandbox Code Playgroud)