I defined a template class FieldSet and a struct TableNode.
Then I tried to claim "FieldSet<TableNode> fieldSet[TableMaxNumber]" in another class called DBOperations.
And then, a link error occured!
Codes and error messages are as following.
Can anyone tell me about my mistake and the way to fix it?
THANKS A LOT!!!
=========================================================================
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
// FieldSet.h: interface for the FieldSet class.
#define MaxSizeDefine 50
#define defaultSize 100
template<class Type> class FieldSet
{
public:
Type *data;
FieldSet(int maxSize = defaultSize);
virtual ~FieldSet();
int find(Type &x) const;
int add(Type &x);
int add(Type &x,int y);
int insert(Type &x,int i,int y);
int remove(int i);
int remove(Type &x);
int getData(Type* x);
int clearData();
private:
int maxSize;
int last;
};
//implementation of the FieldSet class.
template<class Type> FieldSet<Type>::FieldSet(int sz)
{
if(sz>0){
maxSize = sz;
last=-1;
data= new Type[maxSize];
}
}
template<class Type> FieldSet<Type>::~FieldSet()
{
}
......
|
===========================================================================
1 2 3 4 5 6 7 8 9
|
// TableNode1.h
struct TableNode {
char sType[8];
int iSize;
int tableChoice;
char bKey;
char bNullFlag;
char bValidFlag;
};
|
===========================================================================
1 2 3 4 5 6 7
|
// DBOperations.h
#include "TableNode1.h"
#include "FieldSet.h"
.....
private:
TableNode tempTN;
FieldSet<TableNode> fieldSet[TableMaxNumber];
|
===========================================================================
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
// DBOperations.cpp: implementation of the DBOperations class.
DBOperations::DBOperations()
{
tnum=0;
inum=0;
tableChoice=0;
bExist=false;
while(tnum<TableMaxNumber){fnum[tnum]=0; tnum++;}
tnum=0;
}
DBOperations::~DBOperations()
{
}
.......
|
=======================================================================
1 2 3 4 5 6 7 8 9 10 11 12 13
|
ERROR MESSAGES:
|
Linking...
DBOperations.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall FieldSet <struct TableNode>::~FieldSet <struct TableNode>(void)" (??1?$FieldSet@UTableNode@@@@UAE@XZ)
DBOperations.obj : error LNK2001: unresolved external symbol "public: __thiscall FieldSet <struct TableNode>::FieldSet <struct TableNode>(int)" (??0?$FieldSet@UTableNode@@@@QAE@H@Z)
DBOperations.obj : error LNK2001: unresolved external symbol "public: int __thiscall FieldSet <struct TableNode>::add(struct TableNode &)" (?add@?$FieldSet@UTableNode@@@@QAEHAAUTableNode@@@Z)
DBOperations.obj : error LNK2001: unresolved external symbol "public: int __thiscall FieldSet <struct TableNode>::clearData(void)" (?clearData@?$FieldSet@UTableNode@@@@QAEHXZ)
DBOperations.obj : error LNK2001: unresolved external symbol "public: int __thiscall FieldSet <struct TableNode>::add(struct TableNode &,int)" (?add@?$FieldSet@UTableNode@@@@QAEHAAUTableNode@@H@Z)
DBOperations.obj : error LNK2001: unresolved external symbol "public: int __thiscall FieldSet <struct TableNode>::insert(struct TableNode &,int,int)" (?insert@?$FieldSet@UTableNode@@@@QAEHAAUTableNode@@HH@Z)
DBOperations.obj : error LNK2001: unresolved external symbol "public: int __thiscall FieldSet <struct TableNode>::remove(int)" (?remove@?$FieldSet@UTableNode@@@@QAEHH@Z)
Debug/SimpleDBMS_CPP.exe : fatal error LNK1120: 7 unresolved externals
Error executing link.exe.
Creating browse info file...
SimpleDBMS_CPP.exe - 8 error(s), 0 warning(s) |