Multiple files trouble

I have the beginning of a linked list class, it compiles when I have it all as one file, but separating it into multiple files gives me the error "error LNK2019: unresolved external symbol "public: __thiscall List<int>::List<int>(void)" (??0?$List@H@@QAE@XZ) referenced in function _main". I'm not sure what I'm doing wrong.

List.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#ifndef LIST_H
#define LIST_T

template <typename T>
class List {
public:
	struct Node {
		T data;
		Node *next;
	} *head, *tail;
	List();
};

#endif 


List.cpp
1
2
3
4
5
6
#include "List.h"

template <typename T>
List<T>::List() {
	head = tail = 0;
}


main.cpp
1
2
3
4
5
6
7
8
9
#include <iostream>
#include "List.h"

using namespace std;

int main() {
	List<int> l;
	return 0;
}
Template function definition should be in same translation unit as code which uses it.

Translation: All templated functions should be in headers.
Here, i had the same problem and it was solved.

http://www.cplusplus.com/forum/beginner/102971/

plz read some articles before you post something, your question could be already asked by someone and solved already.
Last edited on
Topic archived. No new replies allowed.