it looks good but doesn't compile :(

  • Thread starter Domenico Andreoli
  • Start date

D

Domenico Andreoli

i have a problem with the following code, it does not compile and i do
not understand why.

the interesting thing is that if function call_f is renamed to f the
compiler is happy.

any kind soul has any clue?

thanks
dom


$ g++ -c broken.cpp
broken.cpp: In function `T* call_f(A&)':
broken.cpp:15: error: syntax error before `>' token
$

----------- CUT HERE -----------
// broken.cpp

struct A
{
template<typename T>
T* f()
{
return 0;
}
};

template<typename T>
T* call_f(A& a)
{
return a.f<T>();
}
----------- CUT HERE -----------


-----[ Domenico Andreoli, aka cavok
--[ http://filibusta.crema.unimi.it/~cavok/gpgkey.asc
---[ 3A0F 2F80 F79C 678A 8936 4FEE 0677 9033 A20E BC50
 
Ad

Advertisements

V

Victor Bazarov

Domenico Andreoli said:
i have a problem with the following code, it does not compile and i do
not understand why.

the interesting thing is that if function call_f is renamed to f the
compiler is happy.

any kind soul has any clue?

thanks
dom


$ g++ -c broken.cpp
broken.cpp: In function `T* call_f(A&)':
broken.cpp:15: error: syntax error before `>' token
$

----------- CUT HERE -----------
// broken.cpp

struct A
{
template<typename T>
T* f()
{
return 0;
}
};

template<typename T>
T* call_f(A& a)
{
return a.f<T>();

Change this to

return a.template f said:
}
----------- CUT HERE -----------

I am not sure why gcc needs that 'template' there. According to
3.4.5, there should be no need for that.

Victor
 

Top