Question

Linking... 
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?

indexList.h
indexList.cpp

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?

Was it helpful?

Solution

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) {
    x->_this_function_does_not_exist_ever_();
}

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.

OTHER TIPS

Are you using visual studio then include both the files into the solution and then run.

Since you are using templates, the best way is to include the definition in .H file.

I read something from this book . And here is something it may help you too.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top