Here's the code that causes the error:
Factory.h:
#include <string>
#include <map>
namespace BaseSubsystems
{
template <class T>
class CFactory
{
protected:
typedef T (*FunctionPointer)();
typedef std::pair<std::string,FunctionPointer> TStringFunctionPointerPair;
typedef std::map<std::string,FunctionPointer> TFunctionPointerMap;
TFunctionPointerMap _table;
public:
CFactory () {}
virtual ~CFactory();
}; // class CFactory
template <class T>
inline CFactory<T>::~CFactory()
{
TFunctionPointerMap::const_iterator it = _table.begin();
TFunctionPointerMap::const_iterator it2;
while( it != _table.end() )
{
it2 = it;
it++;
_table.erase(it2);
}
} // ~CFactory
}
And the error I get:
error: no matching member function for call to 'erase' [3]
_table.erase(it2);
~~~~~~~^~~~~
Any tips? Thanks.
Here's the signature of map::erase
in C++98:
void erase( iterator position );
This function takes an iterator
but you're passing a const_iterator
. That's why the code won't compile.
How do I fix this?
In C++11 this isn't even a problem, so it doesn't need fixing. That's because in C++11 the map::erase
function has the following signature, and thus accepts a const_iterator
.
iterator erase( const_iterator position );
If you can't use the new standard, you'll have to change your variables to iterator
instead.
You are passing a const_iterator to a method which expects a plain iterator.
See: http://www.cplusplus.com/reference/stl/map/erase/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With