i've got an "undefined reference" error while trying to compile these 3 files:
---- file1: bla.h ----
template <class T>
class bla {
T abs;
int n;
public:
bla(int num, T el);
int getn();
};
--file 2: bla.cpp---
#include "bla.h"
template <class T>
bla<T>::bla(int num, T el) {
n = num;
abs = el;
}
template <class T>
int bla<T>::getn() {
return n;
}
---file 3:main.cpp---
#include "bla.h"
#include <iostream>
using std::cout;
int main() {
bla<char> mybla(5, 'a');
cout<<mybla.getn();
return 1;
}
i get the next 2 errors:
[Linker error] undefined reference to `bla<char>::bla(int, char)'
[Linker error] undefined reference to `bla<char>::getn()'
Is including the header file not enough?
What can I do?
Thanks.
Tags: