Trouble passing a map by reference

Hello all,

I'm having a problem passing a map by reference; the compiler seems to want to treat it as a _tree of some kind.

I define the following type:

typedef map<int, vector<float> > iHistory;

A simplified version of the code is:

void testFn(const iHistory& vals)
{
iHistory::iterator pos;
pos = vals.begin();
}

When I compile this in Visual Studio 2008, I get the following error:
binary '=' : no operator found which takes a right-hand operand of type 'std::_Tree<_Traits>::const_iterator' (or there is no acceptable conversion)

I do not get this error if I pass by value. The map in question is pretty small, so this won't be too bad, but I don't understand why I get the error in the first place.

Thanks in advance for any suggestions,

Greg


You need to prepend std:: onto symbols from the standard libs.
You could try this:
1
2
3
4
5
typedef std::map<int, std::vector<float> > iHistory;

void testFn(const iHistory& vals)
{
}

Actually I think your error is from trying to assign a non-const iterator from your const map:
1
2
3
4
5
void testFn(const iHistory& vals)
{
	iHistory::const_iterator pos;
	pos = vals.begin();
}

That should work.
Last edited on
Thanks for the quick responses!

The const_iterator suggestion covered it. (I had actually prepended the std namespace in the actual code, but forgot to include it when I transcribed it here.

Cheers,

Greg
Topic archived. No new replies allowed.