Inheritance in a templated class

Hi,
I am building a class structure where the classes are templated. Below is my base class, MapHolder.h:

#ifndef MapHolder_h
#define MapHolder_h
#include "Node.h"
using namespace std;

template<class X> class MapHolder
{
protected:
map<int, X> Map;
typedef typename std::map<int,X>::iterator myIterator;
myIterator iter;
int MaxR;
int MaxPhi;
int MaxZ;

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

int MapHolder::GetRTag(int Tag){
return(Tag-(Tag%10000))/10000;
}
};
#endif

and my inherited class, MapHolderDataPoint:

#ifndef MapHolderDataPoint_h
#define MapHolderDataPoint_h
#include "Node.h"
#include "MapHolder.h"
using namespace std;

template<class X> class MapHolderDataPoint : public MapHolder<X>
{
public:
MapHolderDataPoint::MapHolderDataPoint(){}
MapHolderDataPoint::MapHolderDataPoint(int MaxR_in, int MaxPhi_in, int MaxZ_in):MapHolder<X>(MaxR_in, MaxPhi_in, MaxZ_in){}

void MapHolderDataPoint::DumpCoords(){
for(MapHolder<X>::iter=MapHolder<X>::Map.begin(); MapHolder<X>::iter!=MapHolder<X>::Map.end(); MapHolder<X>::iter++)
cout << MapHolder<X>::iter->first << " " <<
MapHolder<X>::iter->second.GetR() << " " <<
MapHolder<X>::iter->second.GetPhi() << " " <<
MapHolder<X>::iter->second.Getz() << endl;
return;
}
};

#endif


My problem is that in MapHolderDataPoint I need to scope the variables (as seen above: eg MapHolder<X>::iter) declared as protected variables of MapHolder. Otherwise they are not recognised in MapHolder. What is confusing is that when I declare an instance of MapHolderDataPoint, it is making it into the constructor of MapHolder, so I don't understand why it can't see the variables. MapHolderDataPoint is also able to see the member functions of MapHolder. The only thing it can't see are the protected data members. Any ideas?
Cheers,
Ellie
Last edited on
It would be really good if u could tell which compiler are u using.............
Coz i tried to do the same thing on Visual studio 6 and its compiling fine without any errors...... all the variables are recognized without problem.
Topic archived. No new replies allowed.