Templates C++

P

polka

Mitglied
Hi Progger-Menschen,

Ich progge gerade an einem Tool und möchte eine Klasse mit Template proggen.
Erhalte allerdings bei der Compilierung die Fehlermeldung:
/home/polka/Documents/Projects/entropie_final/main.cpp:13: undefined reference to `cSTREAM<short>::cSTREAM()'
/home/polka/Documents/Projects/entropie_final/main.cpp:16: undefined reference to `cSTREAM<short>::Initialize(char const*)'
/home/polka/Documents/Projects/entropie_final/main.cpp:20: undefined reference to `cSTREAM<short>::Begin()'
/home/polka/Documents/Projects/entropie_final/main.cpp:25: undefined reference to `cSTREAM<short>::Update()'
/home/polka/Documents/Projects/entropie_final/main.cpp:26: undefined reference to `cSTREAM<short>::End()'
/home/polka/Documents/Projects/entropie_final/main.cpp:28: undefined reference to `cSTREAM<short>::~cSTREAM()'
/home/polka/Documents/Projects/entropie_final/main.cpp:28: undefined reference to `cSTREAM<short>::~cSTREAM()'
/tmp/cc7Nerco.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
/tmp/ccOAd82y.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
/usr/lib/gcc/i586-suse-linux/4.1.0/../../../../i586-suse-linux/bin/ld: link errors found, deleting executable `entro'
collect2: ld returned 1 exit status

Weiss jemand warum das passiert, ich habe alle Vorschriften befolgt...

Der SourceCode:
*.h

template <class T>
class cSTREAM {
public:
cSTREAM(void);
~cSTREAM(void);
public:
bool Initialize(const char*);
bool Begin(void);
void Update(void);
void End(void);
private:
FILE* File;
unsigned long Size;
T* pStart;
T* pCurrent;
T* pStop;
T* pEnd;
};

*.cpp

template <class T>
cSTREAM<T>::cSTREAM(void) {
File = NULL;
Size = cSize;
pStart = pCurrent = pStop = pEnd = NULL;
}

template <class T>
cSTREAM<T>::~cSTREAM(void) {
if(pStart != NULL)
delete[] pStart;
if(File != NULL)
fclose(File);
}

template <class T>
bool cSTREAM<T>::Initialize(const char* filename) {
if((File = fopen(filename,"r")) == NULL)
return false;

Size = cSize;
pStart = (T*) new T[Size+1];
pCurrent = pStart;
pEnd = pStart + Size - 1;
*(pEnd+1) = (T)NULL;

return true;
}

template <class T>
bool cSTREAM<T>::Begin(void) {
fseek(File,0,SEEK_SET);
unsigned long size = fread(pStart,sizeof(T),Size,File);
pStop = pStart + size - 1;
pCurrent = pStart;
return (size > 0);
}

template <class T>
void cSTREAM<T>::Update(void) {
fseek(File,pCurrent - pEnd,SEEK_CUR);
unsigned long size = fread(pStart,sizeof(T),Size,File);
pStop = pStart + size - 1;
pCurrent = pStart;
Test(pStart);
}

template <class T>
void cSTREAM<T>::End(void) {
pCurrent = NULL;
pStop = NULL;
}

Bitte um Help...
 
probier mal aus, dass du die funktionen direkt in die klasse hinen schreibst
 
Moin,

siehe http://gcc.gnu.org/bugs.html#known:

Most C++ compilers (G++ included) do not yet implement export, which is necessary for separate compilation of template declarations and definitions. Without export, a template definition must be in scope to be used. The obvious workaround is simply to place all definitions in the header itself. Alternatively, the compilation unit containing template definitions may be included from the header.

MFG skop
 
Ach ich habe den Fehler gefunden, beim compilieren gab ich die falschen files an... aber danke
 

Ähnliche Themen

NagiosGrapher 1.7.1 funktioniert nicht

dovecot und postfix Konfiguration Problem

'libraryname': undefined reference to 'functionname'

popen

#include <readline/readline.h> geht nicht

Zurück
Oben