I am having a bit of trouble with a c++ class that I am trying to implement.
I subclass std::vector but I can't get the iterator. Here's my sample code:
This line "MyPairList::iterator Item = this->begin();" I can't get the iterator to my template class.
How can I fix this and why exactly is it happening because right now I am totally at a loss. Also this is all described in my .h file, no .cpp file.
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
template<typename T>
class MyPairList : public vector<T>
{
public:
void Form()
{
_idColl.clear();
_nameColl.clear();
MyPairList::iterator Item = this->begin();
for ( ; Item != this->end() ; ++Item)
{
_idColl.insert(make_pair( (*Item)->ID, (*Item) ));
_nameColl.insert(make_pair( (*Item)->Name, (*Item) ));
}
}
T Lookup(int pID)
{
if (_idColl.find(pID) != _idColl.end())
{
return _idColl[pID];
}
return T();
}
T Lookup(const string &pName)
{
if (_nameColl.find(pName) != _nameColl.end())
{
return _nameColl[pName];
}
return T();
}
MyPairList()
{
}
private:
unordered_map<int, T> _idColl;
unordered_map<string, T> _nameColl;
};
Aucun commentaire:
Enregistrer un commentaire