'The iterator type in this range-based for is "int" in my custom linked list
I'm trying to iterate over my linked list, but VSC keeps complaining that my range-based for isn't suitable for this. It says
"the iterator type in this range-based 'for' statement is "int", which is not a pointer type or an iterator-like class type"
LinkedList<int> list;
/*
insert operations
*/
for(int i: list){
cout << i << endl;
}
I also declared the begin and end functions in the .hpp:
T begin(){
return head->data;
}
T end(){
return tail->data;
}
I know it isn't supposed to work properly, but at least I expect to get a return for the first element. I'm not familiar with C++, I just want to create a range-based for like this:
for(T type: list){}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
