Cincai Patron
why this simple codes fail to compile (error during linking)? /************************ Kelas.h **********************/ template<typename T> class Kelas { public: Kelas(); int getInt() const; };
/************************ Kelas.cpp **********************/ #include "Kelas.h"
template<typename T> Kelas<T>::Kelas() {
}
template<typename T> int Kelas<T>::getInt() const { return 100; }
/*********************** coba.cpp ***************************/ #include <iostream> #include "Kelas.h" using namespace::std;
int main() { Kelas<int> k; cout << k.getInt() << endl; } /*********************** end of coba.cpp ***************************/
The compiler has to see the complete definition of a template in order to instantiate it where needed (that is, until it supports the 'export' keyword). I'd therefor suggest to include Kelas.cpp in Kelas.h. Philipp -- Philipp Thomas work: pthomas@suse.de private: philipp.thomas@t-link.de