Question about storing array in a std::vector in C++

前端 未结 7 1346
灰色年华
灰色年华 2021-01-12 17:07

I am unclear about the following.

First, this code compiles fine:

#include 

typedef struct{
    int x1,x2,x3,x4;
}  ints;

typedef std         


        
7条回答
  •  渐次进展
    2021-01-12 17:31

    Under the hood it's doing an assignment and that isn't defined for arrays.

    The pertinent part of the error is

    instantiated from here /usr/lib/gcc/i586-redhat-linux/4.4.1/../../../../include/c++/4.4.1/bits/vector.tcc:306: error: array must be initialized with a brace-enclosed initializer /usr/lib/gcc/i586-redhat-linux/4.4.1/../../../../include/c++/4.4.1/bits/stl_vector.h:741: instantiated from ‘void std::vector<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = int [4], _Alloc = std::allocator]’ test2.cpp:9: instantiated from here /usr/lib/gcc/i586-redhat-linux/4.4.1/../../../../include/c++/4.4.1/bits/vector.tcc:312: error: invalid array assignment

提交回复
热议问题