On Sunday 20 July 2003 13:26, Philipp Thomas wrote:
Cincai Patron
[Sun, 20 Jul 2003 11:42:23 +0800]: 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
Many libraries offer classes as templates, you only have to include the headers then. This should be possible here as well, what are the error messages of the linker? best, Jeroen -- Kile - a LaTeX editor for KDE http://kile.sourceforge.net