I'm trying to convert a class from an "ordinary" class to a template class, and I don't understand the correct syntax. Below is a (greatly simplified) example of what I'm starting with. This is Visual Studio 2010, C++, targeted to x64 architecture, Windows 7.
The goal is to rewrite class T as a template to handle either TEntry or a new class, OtherTEntry, similar to TEntry in concept, with the same member functions, but having different data members.
I'd appreciate advice on how best to do this. I'd like to keep the header and implementation files separate, if possible. I am particularly stuck on the references to a local variable T *, and how to use sizeof() properly.
In file T.h:
class T
{
T(void);
T(G *pGIn, const unsigned long s, char nIn);
~T(void);
// Member functions
public:
bool Expand(const unsigned long newS);
void Empty(void);
private:
G *pG;
char n;
unsigned long s;
int f;
TEntry *p;
};
In file TEntry.h:
class TEntry
{
// Constructors
public:
TEntry();
TEntry(int l);
// Member functions
public:
void Relocate(int delta);
private:
// Data members
int k;
TEntry *p;
};
In file T.cpp:
T::T()
{
p=NULL; s=0; pG=NULL;
Empty();
return;
}
T::T(G *pGIn, const unsigned long m, char nIn)
{
pG=pG; n=nIn;
return;
}
T::~T(void)
{
if(p!=NULL)
delete[] p;
return;
}
bool T::Expand(const unsigned long newS)
{
T *pBefore=p;
p=(T *)_realloc_dbg(p, newS*sizeof(T), _NORMAL_BLOCK,__FILE__,__LINE__);
s=newS;
return p!=NULL;
}
void T::Empty()
{
f=0;
return;
}
In file TEntry.cpp:
T::T()
{
}
T::T(int i)
{
k=i;
}
void T::Relocate(int delta)
{
k+=delta;
return;
}
std::vector
?