Hi,

Here is a snippet that does not compile with gcc 3.4.1 (on Mandrake 10.1).

---------------------------------------------------
template <class T> class A
{
public:
  template <class U> void test(T value) {}
};

template <class T> void test2(A<T>& a, T val)
{
  a.test<int>(val);
}

int main()
{
  A<int> a;
  a.test<int>(1); //works fine
}
---------------------------------------------------

$ g++ -o test test.cc
test.cc: In function `void test2(A<T>&, T)':
test.cc:9: error: expected primary-expression before "int"
test.cc:9: error: expected `;' before "int"

The funny thing is that if I change the name of the "test2" function to 
"test", everything is OK. The compiler complains only if the functions have 
different names. Why does the name matter?

The code compiles if "test2" is not a template function. Furthermore, calling 
A<T>::test directly from main rather than through the template function works 
fine.

I don't know if this is really a compiler thing, but it's hard to imagine the 
standard would impose such behavior.

Please cc your thoughts to me, I'm not a subscriber.

Thanks.
-Topi-

Reply via email to