www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/03/16/15:34:42

Date: Thu, 16 Mar 1995 11:08:12 -0800 (PST)
From: Gordon Hogenson <ghogenso AT u DOT washington DOT edu>
To: Erik Laumb Jensen <jensen AT nora DOT gih DOT no>
Cc: djgpp AT sun DOT soe DOT clarkson DOT edu
Subject: inline template functions

On Thu, 16 Mar 1995, Erik Laumb Jensen wrote:

> 
> test.cc: In function `int main()':
> test.cc:1: warning: can't inline call to `void tSwap(int &,int &)'
> Am I missing something here? I know that the 'inline' keyword is a request

> only, but if template functions can't be inlined (where the equivalent 
> non-template function can), I'd just as well write macros.  As I 

Current version of g++ can't inline template functions on their *first* use.
This is a limitation, and is caused by the fact that the template function
is instantiated at that point.  

To get around this, just add an explicit instantiation directive to your
file,

template void tSwap(int&, int&);

or something like that.  This will cause the template to be instantiated
at that point, so that it can be expanded inline when it is actually used.

--
Gordon J. Hogenson <ghogenso AT u DOT washington DOT edu>         Tel. (206) 685-2951

- Raw text -


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