【发布时间】:2016-11-07 23:30:59
【问题描述】:
#include <vector>
using namespace std;
vector<int[60]> v;
int s[60];
v.push_back(s);
Visual Studio 2015 社区中的这段代码报告编译错误:
错误(活动)没有重载函数实例“std::vector<_ty _alloc>::push_back [with _Ty=int [60], _Alloc=std::allocator]”与参数列表匹配
错误 C2664 'void std::vector>::push_back(const int (&)[60])':无法将参数 1 从 'int' 转换为 'int (&&)[60]'
【问题讨论】:
-
你应该使用std::array,原始数组很挑剔,一旦你看到它们就会衰减到指向它们的第一个元素的指针。
-
int[10] s;是一个语法错误,您也应该在该行遇到问题。v.push_back(s)也必须出现在函数内部 -
对不起,我弄错了