tags:

views:

195

answers:

2

After researching this online, I've only found solutions that don't apply to my problem, so please bear with me. Code snippet:

typedef map<int const *, float> my_map_t;
my_map_t _test;
my_map_t::const_iterator not_found = my_map_t::end();
if (_test.find(&iKeyValue) == not_found) {
   _test[iKeyValue] = 4 + 5; // not the actual code, but here for simplicity
}

The compiler complains that there's an ambiguous call to my_map_t::end(). This makes sense, because the only difference is the return type.

Output:

error C2668: 'std::_Tree<_Traits>::end' : ambiguous call to overloaded function

Normally you can disambiguate the call by casting the parameters, but end() has no parameters. Any ideas?

+2  A: 

From your code, it appears that my_map_t::end() is static (otherwise you'd have to call it on an instance, e.g. _test.end()). Edit: Jesse Beder is right in his comment to the question; the code doesn't make much sense, since _test is a type, not an object.

Static member functions cannot be const-qualified (the const-qualification of a member function applies to the this pointer; static member functions have no this pointer).

James McNellis
D'oh! Thanks, I knew I forgot something.
Joe
A: 

I don't know if this speaks, exactly, to your problem because I'm a little unclear on how to interpret the question but this might be of help...

// BindingProblem.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <map>

typedef std::map<int*, float> my_map_t;

int _tmain(int argc, _TCHAR* argv[])
{
    int iKeyValue;

    my_map_t _test;

    my_map_t::const_iterator not_found = _test.end();

    if (_test.find(&iKeyValue) == not_found)
    {
        _test[&iKeyValue] = 4 + 5; // not the actual code, but here for simplicity
    }

    return 0;
}