[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
 

Re: [PROGRAMMERING] C++ templates







Anders Melchiorsen <sslug@sslug> wrote on 09-05-2004
18:27:24:

> Henrik Brix Andersen <sslug@sslug> wrote:
>
> > Kan det passe at GCC's g++ ikke vil acceptere at en template-klasses
> > medlemsfunktioner er erklæret uden for den pågældende
> > template-klasses definition?
>
> Ja, det er rigtigt nok. Du skal bruge "export" for at opnå det, du
> ønsker. Det kan dog godt blive svært, da "export" ikke er understøttet
> af GCC (eller stort set nogen anden C++ compiler).


En anden mulighed er explicit inanciering af de C++ klasser der skal bruges
i en source fil:

Ex:

// foo.cc:
#include foo.cpp // include the template function definitions

// explicit instanciation af foo<int>
template foo<int>;

// explicit instanciation af foo<int>
typedef foo<bar> foo_bar;
template foo_bar;

link object filen med det øvrige og alt skulle virke.


bemærk at foo<int> kun må være instancieret i et kompilationsmodul.


Personlig ville jeg vende om på brugen af .cpp og .cc og lade .cc filen
følge .h i include directory.


En tredie mulighed er at definere funktioner i header filen uden for
klasse-definitionen og så erklære dem inline.


Med venlig hilsen

Nils Åke Ljunggren

                                                                       
                                                                       
                                                                       
 Senior                                   IntraVision                  
 Developer                                                             
                                                                       
                                                                       
                                                                       
 Mail:          sslug@sslug        Lyngsø Alle 3,             
                                          2970 Hørsholm,             
                                          Denmark                      
                                                                       
 Direct:        +45 7023 2340             Office:        +45 7023 2340 
                                                                       
 Mobile:        +45 2613 9966             Fax:           +45 7023 2349 
                                                                       
                                          Web:           www.intravision.dk
                                                                       
                                                                       
                                                                       



This e-mail may contain confidential information and is intended only for
the addressee. If you have received this e-mail by mistake, please notify
the sender and delete this mail.

Anders Melchiorsen <sslug@sslug> wrote on 09-05-2004
18:27:24:

> Henrik Brix Andersen <sslug@sslug> wrote:
>
> > Kan det passe at GCC's g++ ikke vil acceptere at en template-klasses
> > medlemsfunktioner er erklæret uden for den pågældende
> > template-klasses definition?
>
> Ja, det er rigtigt nok. Du skal bruge "export" for at opnå det, du
> ønsker. Det kan dog godt blive svært, da "export" ikke er understøttet
> af GCC (eller stort set nogen anden C++ compiler).
>
> (Du har vist fået byttet om på betydningen af "erklære" og "definere")
>
>
> Anders.


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 22:43 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] *