delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/12/03/10:02:14

Message-ID: <34857459.AA287A6F@no.spam.mcs.nl>
Date: Wed, 03 Dec 1997 16:01:45 +0100
From: "A.P. Zijlstra" <peter AT no DOT spam DOT mcs DOT nl>
Reply-To: peter AT no DOT spam DOT mcs DOT nl
Organization: Physics student @ University of Amsterdam
MIME-Version: 1.0
To: bena AT sirplc DOT co DOT uk DOT mcs DOT nl
CC: djgpp AT delorie DOT com
Subject: Re: Template Classes
References: <3483fe9f DOT 11764438 AT news DOT areti DOT co DOT uk>

Ben Ashley wrote:
> 
> Hey All,
> 
> Over the past few days I have been developing some template classes
> with DJGPP.  Unfortunately, I have been hitting a few problems.
> 
> At first, I was getting an undefined reference to whatever member
> function I was accessing.  To get around this, the solution seemed to
> be to either include all functions definitions, in the declaration of
> the class, ie:
> 
> template< class TYPE >class A
> {
> public:
>         A()
>         {
>                 // A Constructor
>         };
> 
>         ~A()
>         {
>                 // A Destructor
>         };
> 
>         void AFunction()
>         {
>                 // A Function
>         };
> 
>         // etc...
> };
> 
> This, however, looked horrid, and could very quickly become
> unmanageable...  An alternative method was to split them up into the
> usual .h, and .cc file, but implictily include the .cc file in the .h
> file....
> 
> File: a.h
> ---------
> 
> template< class TYPE >class A
> {
> public:
>         A();
>         ~A();
> 
>         void AFunction();
> };
> 
> #ifndef A_IMPLEMENTATION
> #define A_IMPLEMENTATION
> 
> #include "a.cc"
> 
> #endif // A_IMPLEMENTATION
> 
> File: a.cc
> ----------
> 
> template< class TYPE >
> A< TYPE >::A()
> {
>         // A Constructor
> };
> 
> template< class TYPE >
> A< TYPE >::~A()
> {
>         // A
> };
> 
> template< class TYPE >
> void A< TYPE >::AFunction()
> {
>         // Some meaningless function
> };
> 
> However, the problem with both of the above methods is the overhead of
> the object files.  Surely, having the implementation with the header
> file ( same in both cases ), will mean that each object file that
> includes these files will have the entire implementation aswell.
> 
> Will DJGPP strip out the extra stuff at link time?  Does it have the
> intelligence to realise that alot of the content in these object files
> is similar?
> 
> Is there a method whereby I don't have to include the implementation
> to be able to use template-class functionality?
> 
> I did read up on the Template Instantation section of the DJGPP
> documentation, but unfortunately, like the rest of the DJGPP
> documentation, it leaves a lot to be desired.
> 
> Anyone's comments would be gratefully appreciated.
> 
> Cheers,
> 
> Ben Ashley -  (Anti-Spam EMail Address.  Remove 'NOSPAM')
> 
> Programmer for Systems Integrated Research Plc
> "Winnie says he's *Not* In-Animate"
Hi,

looks like you ran into the template instantiation limitation in GCC
too, check this one ftp://ftp.cygnus.com/pub/g++/gcc-2.7.0-repo.gz

greetinx,

Peter

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019