Mail Archives: djgpp/1995/03/16/09:56:15
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 -