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

Date: Thu, 16 Mar 1995 13:49:15 +0100 (GMT+0100)
From: Erik Laumb Jensen <jensen AT nora DOT gih DOT no>
To: djgpp AT sun DOT soe DOT clarkson DOT edu

Trying to complile the code 'test.cc':

------------------------------------------
template <class T> inline void tSwap(T   &a, T   &b) { T   tmp(a); a=b; b=tmp; }
                   inline void iSwap(int &a, int &b) { int tmp(a); a=b; b=tmp; }

main()
{
    int a,b;
    iSwap(a,b);
    tSwap(a,b);
}
------------------------------------------

with 

  gcc -O -Winline test.cc -o test

I get the error messages:

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 
understand, one of the reasons for templates in the first place was to 
have a type-safe alternative (and without possible bi-effects) to 
macros.

- Raw text -


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