[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




>-----Original Message-----
>From: Henrik Brix Andersen [mailto:sslug@sslug
>Sent: Sunday, May 09, 2004 5:25 PM
>To: sslug@sslug
>Subject: [PROGRAMMERING] C++ templates
>
>
>Hej,
>
>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?
>
>Eksempel: Nedenstående filer givende følgende fejl under linkning:
>
>
>// foo.h
>#ifndef __TEMPLATE_TEST_H__
>#define __TEMPLATE_TEST_H__
>
>template<class T>
>class foo
>{
>public:
>  void setBar (T bar);
>  T    getBar (void);
>private:
>  T myBar;
>};
>
>#endif  /*  __TEMPLATE_TEST_H__  */
>// EOF foo.h
>
>
>// foo.cpp
>#include "foo.h"
>
>template<class T>
>void
>foo<T>::setBar (T bar)
>{
>  myBar = bar;
>}
>
>template<class T>
>T
>foo<T>::getBar (void)
>{
>  return myBar;
>}
>// EOF foo.cpp
>

Her kan du kun lave instanciering(sp?) af konkrete typer som Niels(?) også skrev, du skal tænke på at hver object fil er en separat kompileringsenhed der skal kende alle type på kompile tid, hvilket betyder at der ikke er lavet en instanciering af foo<int> på link tidspunktet, der er flere måde at snyde på, fx. kan man lave en variable af den type der skal brugers i foo.cpp, fx. foo<int> dummyfoo; jeg er dog ikke klar over om en typedef i foo.cpp er nok, men du kan jo prøve typedef foo<int> fooint; eller om kompilerne er så dumsmarte at de kan se den ikke bliver brugt og ignorere den.


 
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] *