Error: the conversion from ‘STD: : _List_const_iterator & lt; _Mylist> To non-scalar Type ‘STD ::_List_iterator< _Mylist> ‘the requested
Error C2440 resolved: “Initialize” : cannot be retrieved from “STD ::_List_const_iterator< _Mylist & gt;” Into “STD: : _List_iterator & lt; _Mylist & gt;”
Writing C++ code often USES const as a function argument, which is easy to do when using iterator if the variable is of type STL or contains type STL.
void list_print(const list<int> &list)
{
for (list<int>::iterator iter = list.begin();
iter != list.end();
++iter) {
...
}
}
The following error will be reported in this case
error C2440: “initialize”: cannot “std::_List_const_iterator<_Mylist>” to “std::_List_iterator<_Mylist>”
or
error: conversion from 'std::_List_const_iterator<_Mylist>' to non-scalar type 'std::_List_iterator<_Mylist>' requested
Here, because list itself is of type const, we need to use a const-type iterator, which is list::const_iterator
Code to
void list_print(const list<int> &list)
{
for (list<int>::const_iterator iter = list.begin();
iter != list.end();
++iter) {
...
}
}
done
Read More:
- How to Fix Cannot convert value of type Error
- [Solved] MindSpore Error: Data type conversion of ‘Parameter’ is not supporte
- [Solved] Conversion not supported for type java.time.LocalDateTime
- How to Solve Springboot Error: Failed to convert value of type
- How to Fix msgsend() error: to many arguments to function call, expected 0, have2
- How to Solve Error: Element ‘dependency’ cannot have character [children], because the type’s content type is element-
- [Solved] Opencv Call yolov3 Error: IndexError: invalid index to scalar variable
- (How to Fix) Ora-00600: internal error code, arguments: [4194]
- How to Fix Error 1069:The service did not start due to a logon failure
- How to Fix NSS error 12190 in curl accessing to HTTPS
- How to Fix Failed to load resource: the server responded with a status of 404()
- How to Solve Error: Type mismatch: cannot convert from Object to Car
- Websocket: How to Fix Error Read Econnreset
- How to Fix TNS 12560 Error
- How to Fix Error return arrays must be of arraytype
- Start failure: spawn CMD enoent error (How to Fix)
- How to Fix win10 video dxgkrnl fatal error
- How to Fix Spoolsv.exe Application Error
- C++ Compile Error: error: invalid conversion from ‘void*‘ to ‘char*‘ [-fpermissive]