map::iterator error

B

Benny Hill

I have the following:

//-----------------------
typedef std::map<wxString, const void*> MethodMap;
MethodMap mMethods;

const void* hePlugin::GetMethod(const wxString& name) const{
const MethodMap::iterator pos = mMethods.find(name); <== error
if (pos != mMethods.end()){ return pos->second; }
return 0;
}

When I compile this (gcc 3.2.2 on Redhat 9) I get this error for the line
indicated above:

conversion from
`std::_Rb_tree_iterator<std::pair<const wxString, const
void*>, const std::pair<const wxString, const void*>, const
std::pair<const wxString, const void*>*>` to non-scalar type
`std::_Rb_tree_iterator<std::pair<const wxString, const
void*>, std::pair<const wxString, const void*>, std::pair<const wxString,
const void*>*>`

I'm following an example in "The C++ Standard Library: A Tutorial and
Reference" by Josuttis.

I can see that the problem is the missing "const" modifier on the
std::pair's but I don't know how to fix it.

Any help?
 
M

Max M.

Benny said:
const void* hePlugin::GetMethod(const wxString& name) const{
const MethodMap::iterator pos = mMethods.find(name); <== error

MethodMap::const_iterator pos = mMethods.find(name);

MM
 
D

David Fisher

Benny Hill" said:
I have the following:

//-----------------------
typedef std::map<wxString, const void*> MethodMap;
MethodMap mMethods;

const void* hePlugin::GetMethod(const wxString& name) const{
const MethodMap::iterator pos = mMethods.find(name); <== error
if (pos != mMethods.end()){ return pos->second; }
return 0;
}

I'm following an example in "The C++ Standard Library: A Tutorial and
Reference" by Josuttis.

I can see that the problem is the missing "const" modifier on the
std::pair's but I don't know how to fix it.

Use MethodMap::const_iterator instead of const MethodMap::iterator ...

David F
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,150
Messages
2,570,853
Members
47,394
Latest member
Olekdev

Latest Threads

Top