- Nov 16, 1999
- 638
- 0
- 0
Ok, first off I'm in the process of learning Visual C++ after working on Unix systems for the past 4 years. The problem I'm having is as follows: my template array class refuses to compile. I'm suspecting that it has something to do with not generating the proper object files (though it could simply be programmer error). Here's a small snippet:
template <class ArrayType> class Array1
{
protected:
Array1(){}
int x;
ArrayType *array;
public:
Array1(const int &i);
~Array1(){if(array) delete [] array;}
void set(const int &i, const ArrayType &a){array[ i ] = a;}
ArrayType get(const int &i){return array[ i ];}
};
template <class ArrayType> Array1<ArrayType>::Array1(const int &i)
{
x = i;
array = new ArrayType[x];
}
Everything compiles just fine when I stick everything in the header file, but when I move the constuctor (destructor/functions) over to a cpp file I get the following error(s):
hello.obj : error LNK2001: unresolved external symbol "public: __thiscall Array1<float>::Array1<float>(int const &
" (??0?$Array1@M@@QAE@ABH@Z)
Debug/hello.exe : fatal error LNK1120: 1 unresolved externals
Any help would be appreciated.
edit - just realized [ i ] makes the text go italic with no spaces...
template <class ArrayType> class Array1
{
protected:
Array1(){}
int x;
ArrayType *array;
public:
Array1(const int &i);
~Array1(){if(array) delete [] array;}
void set(const int &i, const ArrayType &a){array[ i ] = a;}
ArrayType get(const int &i){return array[ i ];}
};
template <class ArrayType> Array1<ArrayType>::Array1(const int &i)
{
x = i;
array = new ArrayType[x];
}
Everything compiles just fine when I stick everything in the header file, but when I move the constuctor (destructor/functions) over to a cpp file I get the following error(s):
hello.obj : error LNK2001: unresolved external symbol "public: __thiscall Array1<float>::Array1<float>(int const &
Debug/hello.exe : fatal error LNK1120: 1 unresolved externals
Any help would be appreciated.
edit - just realized [ i ] makes the text go italic with no spaces...
