Dưới đây là đoạn code mà gây ra lỗi:không có chức năng thành viên phù hợp cho cuộc gọi đến 'xóa'
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
}
Và lỗi tôi nhận được:
error: no matching member function for call to 'erase' [3]
_table.erase(it2);
~~~~~~~^~~~~
Bất kỳ lời khuyên? Cảm ơn.
nhu cầu của 'it2' là gì? Làm thế nào về '_table.erase (it ++)'? – iammilind