I must be overlooking something here, but I get the following errors
Code:
:C:\C++Projects\test\main.cpp:9: undefined reference to `X_Container<char>::X_Container()'
:C:\C++Projects\test\main.cpp:9: undefined reference to `X_Container<char>::~X_Container()'
:: === Build finished: 2 errors, 0 warnings ===
The class declaration looks like this
Code:
#ifndef CLASS_H
#define CLASS_H
/*************/
template<class Param>
class X_Container
{
public:
X_Container();
X_Container(int Size);
~X_Container();
void Insert(Param type, int Pos);
void Remove(Param type, int Pos);
void Clear();
long Size();
bool Resize(int size);
bool AddSize(int amount);
private:
Param* type;
int size_;
};
/*************/
#endif
The implementation is as follows, and I have look up and down this, and cant find the problem.
Code:
#include "class.h"
/****************/
template<class Param>
X_Container<Param>::X_Container()
{
//Default small size
size_ = 1000;
//Dynamically allocate memory for the type
type = new Param[size_];
}
template<class Param>
X_Container<Param>::X_Container(int Size)
{
//User Selected Size
size_ = Size;
//Dynamically allocate memory for the type
type = new Param[size_];
}
template<class Param>
X_Container<Param>::~X_Container()
{
//Set all pointers to null
for ( int iter = 0; iter != size_; ++iter )
{
type[iter] = 0;
}
delete []type;
}
template<class Param>
void X_Container<Param>::Insert(Param type, int Pos)
{
//
}
template<class Param>
void X_Container<Param>::Remove(Param type, int Pos)
{
//
}
template<class Param>
void X_Container<Param>::Clear()
{
//
}
template<class Param>
long X_Container<Param>::Size()
{
return size_;
}
template<class Param>
bool X_Container<Param>::Resize(int size)
{
//
}
template<class Param>
bool X_Container<Param>::AddSize(int amount)
{
//
}
The problem is when I try to declare a instance of the class I get the undefined errors.
This is how I was declaring it.
Code:
X_Container<int> A(25);
Thank you for your assistance.