error: conversion from 'std::_List_const_iterator<_Mylist>' to non-scalar type 'std::_List_iterator<
来源:互联网 发布:什么是php网站 编辑:程序博客网 时间:2024/06/16 15:10
error: conversion from ‘std::_List_const_iterator<_Mylist>’ to non-scalar type ‘std::_List_iterator<_Mylist>’ requested
解决error C2440: “初始化”: 无法从“std::_List_const_iterator<_Mylist>”转换为“std::_List_iterator<_Mylist>”
写C++代码经常会使用const作为函数入参,如果这个变量是STL类型或者包含STL类型,在使用iterator时容易会这么使用。
void list_print(const list<int> &list) { for (list<int>::iterator iter = list.begin(); iter != list.end(); ++iter) { ... }}
这个情况下会报如下错误
error C2440: “初始化”: 无法从“std::_List_const_iterator<_Mylist>”转换为“std::_List_iterator<_Mylist>”或者是error: conversion from 'std::_List_const_iterator<_Mylist>' to non-scalar type 'std::_List_iterator<_Mylist>' requested
这里是因为list本身是const类型,需要使用const型的iterator才行,也就是list::const_iterator
代码改为
void list_print(const list<int> &list) { for (list<int>::const_iterator iter = list.begin(); iter != list.end(); ++iter) { ... }}
搞定
阅读全文
0 0
- error: conversion from 'std::_List_const_iterator<_Mylist>' to non-scalar type 'std::_List_iterator<
- 解决error C2440: “初始化”: 无法从“std::_List_const_iterator<_Mylist>”转换为“std::_List_iterator<_Mylist>”
- error: conversion from 'const char [ ]' to non-scalar type
- conversion from 'LinkedList<myInt>*' to non-scalar type 'LinkedList<myInt>' requested
- error: cannot pass objects of non-trivially-copyable type ‘std::string {aka class std::basic_string
- C++引用报错:invalid initialization of non-const reference of type ‘std::string&’ from an rvalue of type
- error C2440: 'initializing' : cannot convert from 'boost::filesystem3::path' to 'std::basic_string<_
- fixed: error C2784 from compiling adding an entry to a std::map
- error: no type named 'string' in namespace 'std'; did you mean 'std::string'? [3]
- Error: ‘shared_ptr’ in namespace ‘std’ does not name a type
- error: no type named 'u16string' in namespace 'std'
- error: no type named 'u16string' in namespace 'std'
- std
- std
- std
- error cannot convert from 'std::_Vector_iterator<_Ty,_Alloc>
- cannot convert parameter 1 from 'std::string' to 'const char *'
- cannot pass objects of non-trivially-copyable type 'std::string ...' through '...'
- 怎么导入github上的maven项目到eclipse中
- gym101431D(传说中的构造(呸))
- cocos2d-x(lua)的安装和运行helloworld(一)
- LeetCode编程练习
- 什么是CDN?CDN有什么用处?
- error: conversion from 'std::_List_const_iterator<_Mylist>' to non-scalar type 'std::_List_iterator<
- 基于FreeRTOS与MQTT的物联网技术应用系列——步进电机控制(二)FreeRTOS v9.0.0 的移植
- Div+Css布局--iframe的使用
- LeetCode编程练习
- 【安全牛学习笔记】EVIL TWIN AP、ROGUE AP
- Mysql 常用show命令
- Java之HashMap底层实现原理/HashMap、HashTable、HashSet
- ELK中logstash的使用
- Jmeter学习-第一篇