-
std::map error
I have a map that looks like this:
Code:
std::map<std::string, double> table;
When I try this the compiler spews out a bunch of error messages that I don't understand:
Code:
std::string name = "foo";
std::map<std::string, double>::iterator it = table.find(name);
if (it == table.end()) {std::cout << "Variable not found" << std::endl;}
-
What's the error messages?
-
Code:
error: conversion from ‘std::_Rb_tree_const_iterator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, double> >’ to non-scalar type ‘std::_Rb_tree_iterator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, double> >’ requested
-
From the error message, table is probably const is that context, so it should be:
Code:
std::map<std::string, double>::const_iterator it = table.find(name);
-
Yeah I figured it out. table is not declared const, but the member function this error occurred in was. I didn't think that would affect things like that.