C++: templates

zvyagin@gams.ihep.su zvyagin@gams.ihep.su
Thu Jul 29 11:24:00 GMT 1999


Dear g++ developers!
 
My friend Alexander Shvorob sent me piece of code that demonstrated
one problem with template arguments.

// File 2.c  ---------------------- CUT HERE ---------
class Store { public: int i1,i2; } s;
template <int *N> class Test {};

int main()
{
  Test<&s.i1> ok; 
  Test<&s.i2> bad;
}
// -------------------------------- CUT HERE ---------

$ g++ 2.c
2.c: In function `int main()':
2.c:8: `(&s + 4)' is not a valid template argument
2.c:8: it must be the address of an object with external linkage
2.c:8: ANSI C++ forbids declaration `bad' with no type

$ g++ -v
Reading specs from
/usr/local/lib/gcc-lib/i686-pc-linux-gnulibc1/2.95/specs
gcc version 2.95 19990718 (prerelease)

With best wishes,
Alexander Zvyagin.




More information about the Gcc-bugs mailing list