C++ map iterator issue
c++, dictionary, gcc, iterator
Solution
You have a const function that is trying to iterate what I assume is a member variable (marks). Make sure you use a const iterator:
for(map<string, float>::const_iterator iter = marks.begin();
Problem
I have a weird error in the following code : ``` float Student::getAverageMark() const throw (NoMarkException) { int sum = 0; int count = 0; for(map<string, float>::iterator iter = marks.begin(); iter != marks.end(); ++iter) { sum += iter->second; count++; } return sum/count; } ``` As you can see, it's nothing out of the ordinary, it's a simple code that calculates the average marks in a map. I tested this in an online compiler and it worked, but when I try to compile it on my machine (I'm using CodeBlocks with the GNU GCC Compiler) I get this error: error: conversion from 'std::map, float>::const_iterator {aka std::_Rb_tree_const_iterator, float> >}' to non-scalar type 'std::map, float>::iterator {aka std::_Rb_tree_iterator, float> >}' requested|