map iterator inside a templated class

Hi,
I have the class pasted below. It fails to compile at the line where I declare the iterator:
map<int, X>::iterator iter;

with error
classes/MapHolder.h:9: error: expected `;' before "iter"

I suspect this might have something to do with it being a templated class as the syntax seems to be correct. Any ideas?

Cheers,
Ellie


#ifndef MapHolder_h
#define MapHolder_h
#include "Node.h"

template<class X> class MapHolder
{
private:
map<int, X> Map;
map<int, X>::iterator iter;

public:
MapHolder::MapHolder(int MaxR, int MaxPhi, int MaxZ){
X Blank;
for(int i=0; i<MaxR; i++){
for(int j=0; j<MaxPhi; j++){
for(int k=0; k<MaxZ; k++)
Map.insert(pair<int, X>(GetTag(MaxR, MaxPhi, MaxZ), Blank));
}
}
}

void Insert(X Object){
int RLabel=Object.GetRLabel();
int PhiLabel=Object.GetPhiLabel();
int ZLabel=Object.GetzLabel();

/*try{
if((RLabel>MaxR)||(RLabel<0))
throw RLabel;
if((PhiLabel>MaxPhi)||(PhiLabel<0))
throw PhiLabel;
if((ZLabel>MaxZ)||(ZLabel<0))
throw ZLabel;
}
catch{int Label){
cout << "Label out of range for map!" << endl;
cout << "Label= " << Label << "Max R Phi Z = " << MaxR << " " << MaxPhi << " " << MaxZ << endl;
return;
}*/

Map.insert(pair<int, X>(GetTag(RLabel, PhiLabel, ZLabel), Object));
return;
}

int GetRTag(int Tag){
return(Tag-(Tag%10000))/10000;
}

int GetPhiTag(int Tag){
return ((Tag-GetZTag(Tag))%10000)/100;
}

int GetZTag(int Tag){
return Tag%100;
}

int GetTag(int RTag, int PhiTag, int ZTag){
return (10000*RTag)+(100*ZTag)+(PhiTag);
}

map<int, X> GetMap(){
return Map;
}

void Dump(){ need to fix the iterators for this to work
for(iter=Map.begin(); iter!=Map.end(); iter++)
cout << iter->first << " " << iter->second.GetR() << " " << iter->second.GetPhi() << " " << iter->second.Getz() << endl;
return;
}
};
#endif

Last edited on
Topic archived. No new replies allowed.