[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

C++ template problem



Hej

Jeg har et (sikkert ret simpelt) problem med at forstå hvordan man får
gcc (g++) til at kompilerere templates ordenligt.

Hvis jeg har følgende miniprogram:


template <class TYPE>
class klasse
{
        public:
                TYPE f();
};

template <class TYPE>
TYPE klasse<TYPE>::f()
{
        // En eller anden funktion
}

int main()
{
        klasse<int> k;
        int i = k.f();
        return 0;
}



og kompilerer den virker det ganske glimrende og jeg får det resultat
jeg gerne vil have. Men hvis jeg forsøger at splitte det op i tre filer,
således at klasse hovedet er i klasse.h, implementationen i klasse.cpp
og main-funktionen i main.cpp får jeg følgende fejl:


sslug@sslug temp]$ g++ -Wall -c klasse.cpp
sslug@sslug temp]$ g++ -Wall main.cpp klasse.o
/tmp/ccKFiPJB.o: In function `main':
/tmp/ccKFiPJB.o(.text+0x11): undefined reference to
`klasse<int>::f(void)'
collect2: ld returned 1 exit status


Jeg kan godt gætte at problemet er, at gcc ikke ved hvilke udgaver af
templateklassen der vil være brug for når den kompilerer klasse.cpp, og
derfor ikke laver en udgave der virker med integers. Men hvordan får man
det til at virke?


Håber der er nogen der kan hjælpe, hilsen Anders


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:09 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *