Search code examples
c++stldictionarymultimapvisual-c++-2012

VC++11 map and multimap iterators (overloading) C2535


I'm just playing with new VS 2012 and I have a problem probably with new C++11. This pease of code work perfectly when I set platform toolset to VS2010 (v100) in project settings.

.h:

typedef std::multimap<unsigned, unsigned>   SizeMap;
typedef std::map<unsigned, unsigned>        OffsetMap;

private:
    inline void _RemoveBlockL(SizeMap::iterator sizeI);
    inline void _RemoveBlockL(OffsetMap::iterator offsetI);

.cpp:

inline void Foo::_RemoveBlockL(SizeMap::iterator sizeI)
{
// impementation
}

inline void Foo::_RemoveBlockL(OffsetMap::iterator offsetI)
{
// impementation
}

But when I change that for VS2012 (v110), I'll get these error:

Error   61  error C2535: 'void
Boo::system::Foo::_RemoveBlockL(std::_Tree_iterator<_Mytree>)' : member function already
defined or declared D:\_work\wp-test\boo\system\foo.h

Why is overloading not working in VC++11?


Solution

  • The two possibilities I can think of are that since _RemoveBlockL is reserved for the compiler, something changed and it's now reserved, or that in the new compiler the two iterators actually alias the same type. Do you actually need different functional behavior depending on whether it's a map or multimap?

    Assuming you do (because of the typedef names), the correct solution is to just not use overloading to solve this problem. Give the functions names that represent what they actually do (or alternately you may be able to use strong_typedef to make a strong alias so you can overload but I can't visualize the full solution).