Gernot Frisch wrote in news:2s*************@uni-berlin.de in
comp.lang.c++:
return a.template eval<F>();
WTF? Never seen C++ like this before. Now, this is totally insane.
Let me get this in my hamster brain:
F is a function of type: double()(double).
And class A's got a member:
template<ftype F> double eval();
Now, class B has a function that will call a 'eval' of an 'A' object
er... No. I'm too stupid. Honestly, can anyone please give me a like
to what you did here?
Well the ".template" is only required here because of a compiler error,
with a conforming compiler, you can write:
return a.eval< F >();
However if 'a' was dependant on a template paramiter (it isn't in the
OP's code) the the compiler needs to be told that object a's eval
member is a template member, otherwise the compiler treats the
above as:
return ((a.eval) < F ) > ();
In this case a syntax error ! however:
struct A
{
template < int N >
void eval( int a );
};
struct B
{
int eval;
}
template < typename T >
void example( T t )
{
t.eval < 10 > ( 13 );
};
Substitute A and B for T in example() and you can see that without
the .template both could (but don't) compile with completely
different symantics.
example() is designed to work with B style object's, i.e. with
a simple eval member.
template < typename T >
void another( T t )
{
t.template eval < 10 > ( 13 );
};
another() above is designed to work with A style object's, i.e.
with a template member function eval.
Rob.
--
http://www.victim-prime.dsl.pipex.com/