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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top