I have pretty much the same issue as unresolved external symbol "public: __thiscall, but since I've defined all my methods, the solution there doesn't apply here.
I have a Node.h with:
template<typename T>
class Node{
public:
Node(T data, Node* next);
}
In Node.cpp, I was sure to put:
#include "Node.h"
template<typename T>
Node<T>::Node(T data, Node* next){
//I doubt that the implementation is relevant.
}
In both files, I #include "stdafx.h"
to cater to visual studios.
Yet, when I try to instantiate a node with:
#include "stdafx.h"
#include "Node.h"
int main(){
Node<int> n = Node<int>(9, nullptr);
return 0;
}
I get:
main.obj : error LNK2019: unresolved external symbol "public: __thiscall Node<int>::Node<int>(int,class Node<int> *)" (??0?$Node@H@@QAE@HPAV0@@Z) referenced in function _main
Just to debunk a few initial theories:
- I have put all the files in the same VC++ project.
- There are no methods declared in the header that are not defined (VC++ has ensured this).
- I instantiate the node in main.cpp, hence the uses of main.obj in the error.
Is there another issue that I don't see (maybe a Node.h crawling the standard library or some VC++ thing I'm missing). Comparing this to older code I have that does work, the only difference I can find is that the old code doesn't use generics. Are the generics the culprit?
Why won't these files link up correctly? How to avoid this in the future?