原来的代码是:
<pre name="code" class="cpp">vector<double> vec1(0.1,0.1); vector<double> vec2(0.2,0.2);两句话出现了26个错误:
错误 10 error C2868: “std::iterator_traits<_Iter>::value_type”: 非法的 using 声明语法;应输入限定名 d:\program files\vs\vc\include\xutility 372 1 charlotte
错误 25 error C2868: “std::iterator_traits<_Iter>::reference”: 非法的 using 声明语法;应输入限定名 d:\program files\vs\vc\include\xutility 376 1 charlotte
错误 20 error C2868: “std::iterator_traits<_Iter>::pointer”: 非法的 using 声明语法;应输入限定名 d:\program filess\vc\include\xutility 375 1 charlotte
错误 5 error C2868: “std::iterator_traits<_Iter>::iterator_category”: 非法的 using 声明语法;应输入限定名 d:\program files\vs\vc\include\xutility 371 1 charlotte
错误 15 error C2868: “std::iterator_traits<_Iter>::difference_type”: 非法的 using 声明语法;应输入限定名 d:\program files\vs\vc\include\xutility 373 1 charlotte
错误 1 error C2825: '_Iter': 当后面跟“::”时必须为类或命名空间 d:\program files\vs\vc\include\xutility 371 1 charlotte
错误 6 error C2825: '_Iter': 当后面跟“::”时必须为类或命名空间 d:\program files\vs\vc\include\xutility 372 1 charlotte
错误 11 error C2825: '_Iter': 当后面跟“::”时必须为类或命名空间 d:\program files\vs\vc\include\xutility 373 1 charlotte
错误 16 error C2825: '_Iter': 当后面跟“::”时必须为类或命名空间 d:\program files\vs\vc\include\xutility 375 1 charlotte
错误 21 error C2825: '_Iter': 当后面跟“::”时必须为类或命名空间 d:\program files\vs\vc\include\xutility 376 1 charlotte
错误 26 error C2664: “void std::vector<double,std::allocator<_Ty>>::_Construct<_Iter>(_Iter,_Iter,std::forward_iterator_tag)”: 无法将参数 3 从“double”转换为“std::input_iterator_tag” d:\program files\vs\vc\include\vector 766 1 charlotte
错误 9 error C2602: “std::iterator_traits<_Iter>::value_type”不是“std::iterator_traits<_Iter>”基类的成员 d:\program files\vs\vc\include\xutility 372 1 charlotte
错误 24 error C2602: “std::iterator_traits<_Iter>::reference”不是“std::iterator_traits<_Iter>”基类的成员 d:\program files\vs\vc\include\xutility 376 1 charlotte
错误 19 error C2602: “std::iterator_traits<_Iter>::pointer”不是“std::iterator_traits<_Iter>”基类的成员 d:\program files\vs\vc\include\xutility 375 1 charlotte
错误 4 error C2602: “std::iterator_traits<_Iter>::iterator_category”不是“std::iterator_traits<_Iter>”基类的成员 d:\program files\vs\vc\include\xutility 371 1 charlotte
错误 14 error C2602: “std::iterator_traits<_Iter>::difference_type”不是“std::iterator_traits<_Iter>”基类的成员 d:\program files\vs\vc\include\xutility 373 1 charlotte
错误 8 error C2146: 语法错误: 缺少“;”(在标识符“value_type”的前面) d:\program files\vs\vc\include\xutility 372 1 charlotte
错误 23 error C2146: 语法错误: 缺少“;”(在标识符“reference”的前面) d:\program files\vs\vc\include\xutility 376 1 charlotte
错误 18 error C2146: 语法错误: 缺少“;”(在标识符“pointer”的前面) d:\program files\vs\vc\include\xutility 375 1 charlotte
错误 3 error C2146: 语法错误: 缺少“;”(在标识符“iterator_category”的前面) d:\program files\vs\vc\include\xutility 371 1 charlotte
错误 13 error C2146: 语法错误: 缺少“;”(在标识符“difference_type”的前面) d:\program files\vs\vc\include\xutility 373 1 charlotte
错误 7 error C2039: “value_type”: 不是“`global namespace'”的成员 d:\program files\vs\vc\include\xutility 372 1 charlotte
错误 22 error C2039: “reference”: 不是“`global namespace'”的成员 d:\program files\vs\vc\include\xutility 376 1 charlotte
错误 17 error C2039: “pointer”: 不是“`global namespace'”的成员 d:\program files\vs\vc\include\xutility 375 1 charlotte
错误 2 error C2039: “iterator_category”: 不是“`global namespace'”的成员 d:\program files\vs\vc\include\xutility 371 1 charlotte
错误 12 error C2039: “difference_type”: 不是“`global namespace'”的成员 d:\program files\vs\vc\include\xutility 373 1 charlotte
将代码改为:
vector<double> vec1={0.1,0.1}; vector<double> vec2={0.2,0.2};则错误消失。
正确的vector初始化的方法是:
vector<T> v1; | vector保存类型为T的对象。默认构造函数v1为空。 |
vector<T> v2(v1); | v2是v1的一个副本。 |
vector<T> v3(n, i); | v3包含n个值为i的元素。 |
vector<T> v4(n); | v4含有值初始化的元素的n个副本。 |
vector<T> v3(a0,a1)不是一种正确的初始化方法,故而出现错误。