T.T.T. T.T.T. - 15 days ago 4x
C++ Question

Linking error in C++ - implementing a indexList

Directory.obj : error LNK2019: unresolved external symbol "public: void __thiscall indexList<class entry,100>::read(class std::basic_istream<char,struct std::char_traits<char> > &)" (?read@?$indexList@Ventry@@$0GE@@@QAEXAAV?$basic_istream@DU?$char_traits@D@std@@@std@@@Z) referenced in function _main

Getting this error and others associated with indexList implementation. I have included all the right files, not sure what this means?



Also, using VS .NET 2003 - They are under the "Source Files" and "Header Files" However, I tested with deleting the indexLish.h and the error doesn't change?


What you have is a class template. This means when the compiler needs to call a function, it will look at your template definition and generate the corresponding code as needed.

For example, the following probably has a compile-time error in it if tried to call it:

template <typename T>
void doSomething(const T& x) {

But as long as you don't call doSomething you won't get errors.

The problem you have is that your header file tells the compiler "hey, these functions exist", but when the compiler tries to generate them it cannot find any definitions. (You cannot "compile" definitions in a source file and link them in, they must be visible to the caller.)

The most common solution is to simply define the entire class template in the .h or .hpp file.