Mailinglist Archive: opensuse-programming (105 mails)
| < Previous | Next > |
Re: [suse-programming-e] compile problem with template class.
- From: Jeroen Wijnhout <wijnhout@xxxxxxxxxxxxxx>
- Date: Sun, 20 Jul 2003 13:46:58 +0200
- Message-id: <200307201346.58240.wijnhout@xxxxxxxxxxxxxx>
On Sunday 20 July 2003 13:26, Philipp Thomas wrote:
> Cincai Patron <cincaipatron@xxxxxxx> [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@xxxxxxx
> private: philipp.thomas@xxxxxxxxx
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
> Cincai Patron <cincaipatron@xxxxxxx> [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@xxxxxxx
> private: philipp.thomas@xxxxxxxxx
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
| < Previous | Next > |