ILLOGIC wrote in news:cb**************************@posting.google.c om in
comp.lang.c++:
Hello,
i am beginner in c++. I hope tobe sufficiently clear and that someone
could help me on this topic. For example i have template function
<typename T> T sin_func(T & x){return sin(x);}
could it be possible that the paramenter of the function is another
template function?
An example would be very helpful
#include <iostream>
#include <ostream>
#include <cmath>
template < typename T >
T sin_func( T const &x )
{
return std::sin( x );
}
template < typename T >
T sin_func_func( T (*sin_func)( T const & ), T const &x )
{
return sin_func( x );
}
int main()
{
std::cout
<< sin_func_func( sin_func< double >, 3.142 / 4 )
<< std::endl
;
/* Alternativly:
sin_func_func< double >( sin_func, 3.124 / 4 );
*/
/* If you have g++ this also works:
sin_func_func( sin_func, 3.142 / 4 );
- i.e. gcc/g++ can deduce T from the second paramiter.
*/
}
I'm 95% sure that the third (g++) commented out invocation in
main() should work (i.e. its standard) but use either of the
other versions for maximum portability (and also when you
haven't got a 'T' paramiter).
HTH.
Rob.
--
http://www.victim-prime.dsl.pipex.com/