最近在使用vector<int[n]>时会报错,如下的程序
#include<iostream>
#include<vector>
using namespace std;
int main()
{
vector<int[2]> tmp;
int pos[2] = {0};
// tmp.push_back(pos);
}
主要问题在push_back,因为vector的push_back不是真的将对象添加到容器中,而是拷贝构造的方式,而对于数组不能直接拷贝,类似如下代码,是不能编译通过的
int pos[2] = {0};
int posa[2] = pos;
所以可以改为
#include<iostream>
#include<vector>
using namespace std;
class tmp{
int pos[2];
};
int main()
{
tmp tmpa;
vector<tmp> v;
v.push_back(tmpa);
}