By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,406 Members | 888 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,406 IT Pros & Developers. It's quick & easy.

it looks good but doesn't compile :(

P: n/a
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
Jul 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"Domenico Andreoli" <ca***@freemail.it> wrote...
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<T>();
}
----------- 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
Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.