views:

102

answers:

3
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?

+1  A: 

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

Vinay
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?
Tommy
Vinay
First one commented out.
Tommy
+1  A: 

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.

J.W.
+1  A: 

Your class is a templated class. This means when the compiler needs to call a function, it will look at your template definition and from that generate the corresponding code.

For example, the following has obvious errors in it:

template <typename T>
void doSomething(const T& something)
{
    ././.a/at983y62pegha9eg;
}

But as long as you don't call "doSomething", you won't get errors. The problem here is that you have this header file that tells the compiler, "Hey, these functions exist" but when the compiler tries to make them, it looks in your .h, but can't find the actual definition; that's because it is in your .cpp file.

This solution has an answer, but no major compiler vendors implement it. The best solution is to simply define the class in the .h file, or #include the .cpp file, such as you have commented out. Now the compiler (and then the file that included your header) knows what the functions look like so it can make correct instances of the template.

GMan