Home » C++ » The generic template class has an external symbol ...

The generic template class has an external symbol error that LNK2019: cannot resolve

we are not in the most of the time to write a program to consider the lack in existing knowledge, two days before the C++ write a sequence table, the result is satisfactory, this is probably because this is life, in your knowledge of the known knowledge gaps you will be very difficult to find here, thanks SYC brother, each post in the VC stage, he gave me a reply, which is SYC let me more love inn.

VC

OK, talk about the error,


here is my error code


http://www.cctry.com/thread-256893-1-1.html


here, I put my code

after my success

SeqList.h


#include
#include
The default size / order table
Const int defaultsize= 10;
/ / class
Template
Class SeqList
{
Public:
SeqList (int, size = defaultsize)
{
The order of the table correspond to the length of judgment / /
If (size > 0)
{
MaxSize = size;
/ / data array
EML = new DateType[size];
}
}
/ / destructor
~SeqList ()
{
The application of array / / is not empty for release
If (EML = = NULL)
{
Delete []eml;
EML = NULL;
}
}
Int, getLength ()
{
Return curLength;
}
/ / insert
Bool insertElem (DateType e);
/ / delete
Bool delElem (int index);
/ / search
DateType findElem (int index);
/ / change
Bool changeElem (int, index, DateType, e);
Private:
DateType *eml;
Int maxSize;
Int curLength;
};
/ / insert
Template
Bool SeqList:: insertElem (DateType, e)
{
If (curLength < maxSize)
{
Eml[curLength] = e;
CurLength++;
Return true;
}
Std:: cout, "insertElem, function, the, Array, is, full", std:: endl;
Return false;
}
/ / delete
Template
Bool SeqList:: delElem (int, index)
{
If (curLength Index & & index > > = 0)
{
For (int i = index; I < curLength; i++)
{
Eml[i] = eml[i + 1];
}
CurLength--;
Return true;
}
Std:: cout, "delElem, function, wrong, index", std:: endl;
Return false;
}
/ / search
Template
DateType SeqList:: findElem (int, index)
{
If (index < index > = 0 & & curLength)
{
Std:: cout, "findElem, function, wrong, index", std:: endl;
Return NULL;
}
Return eml[index];
}
/ / change
Template
Bool SeqList:: changeElem (int, index, DateType, e)
{
If (index < curLength > = 0 & & Index)
{
Eml[index] = e;
Return true;
}
Std:: cout, "changElem, function, wrong, index", std:: endl;
Return false;
}


Test body


#include "SeqList.h""
#include
//success in day 09-01
/ / and Realization of template class declaration must be written in the same header file, otherwise we can not find the corresponding class of functions
Int, main ()
{
/ / use generic classes, and call the constructor
SeqList list (10);
/ / insert value
For (int, I = 0, I, < 10, i++)
{
List.insertElem (I);
}
/ / display value
For (int i = 0; I < list.getLength (); i++)
{
Std:: cout, list.findElem (I), std:: endl;
}
/ / change the value
List.changeElem (3, 5);
List.delElem (4);
/ / display value
For (int i = 0; I < list.getLength (); i++)
{
Std:: cout, list.findElem (I), std:: endl;
}
Char a[10];
Std:: CIN, a;
}


here, that is, there is a small problem, that is, the template class definition and implementation, the general body to uninstall the same header file.


comes from online:


is not clearly defined in the C++ standard, the definition of template class and the realization of the body must be placed in the same file, because the template class is carried out during pre - compilation, if written in two documents, increases the difficulty of realizing the compiler, so most compilers will define templates and the implementations of placement in the same file.VS2005 support separate template class to write, but he was not detected in many other errors, which had to be said to still need a genius brain to solve this problem



copyright notice: This article is original article for blogger. Without permission from blogger,.

must not be reprinted

Latest