delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/06/27/20:14:34

From: Jan Reimers <wolfe!resrch!janr>
Subject: Templates
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Date: Mon, 27 Jun 94 16:55:13 PDT

Hello

I have a question about generating instances of template functions.  I am
using #pragma implementation "file name" and #pragma interface coupled
with typedef statements to control the generation of my template classes.
For example:

//  file maketmpl.cc

#pragma implementation "myclass.h"
#pragma implementation "myclass.cc"

#include "myclass.h"  //Class declaration.
#include "myclass.cc" //Definition of member functions and friend functions. 

typedef MyClass<int>    MakeInt;  //force genration of template code 
typedef MyClass<float>  MakeInt;  //for various parameterized types.

//  end of maketmpl.cc

The compiler then generates code for all the member functions of MyClass BUT
no code for the friend functions!  Borland C++ 4.0 also generates no friend
functions.  Turbo C++ 3.0 does generate all friend functions.  The only way
that I have found to get around this in djgpp and BC4 is to write a messy
little function (called 'junk()'!) which for example, declares instances of
MyClass and calls all friend functions.  This is very messy and difficult to
maintain accuratly.

	Has anybody else out there in email land, encountered the same problem?
If so, what did you do?  I have recently migrated from FORTRAN to C++, so maybe
I am missing something simple.  Any suggestions would be appreciated.

Thanks in advance.


################################

        Jan N. Reimers 
      Research Scientist
    Moli Energy (1990) Ltd.
     Tel:   (604)-465-7911
     FAX:   (604)-465-4398
  email: janr AT molienergy DOT bc DOT ca

################################

- Raw text -


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