Re: "Function template" problem

From: Gernot Frisch (Me_at_Privacy.net)
Date: 09/30/04


Date: Thu, 30 Sep 2004 10:02:08 +0200


"Lionel B" <google@lionelb.com> schrieb im Newsbeitrag
news:e1308e8b.0409292355.34df10ed@posting.google.com...
> Greetings,
>
> I cannot figure out why the following code does not compile:
>
> --- BEGIN CODE ---
>
> typedef double ftype(double);

what you do is:
template <double f> double func(f x);
But: You don't want to give the type of the template argument, since
it's a "template".
So, use

template<class C> double fkt(C argC);

>
> struct A
> {
> double x;
>
> template<ftype F>
> double eval()
> {
> return F(x);
> }
> };
>
> template<ftype F>
> struct B
> {
> A a;
>
> double foo()
> {
> return a.eval<F>();
> }
> };
>
> --- END CODE ---
>
> It generates the error message:
> scratch.cpp: In member function `double B<F>::foo()':
> scratch.cpp:23: error: parse error before `;' token
>
> [ line 23 being return a.eval<F>(); ]
>
> Compiler gcc (GCC) 3.3.3 (cygwin special) on Win2K
>
> Any help appreciated,
>
> --
> Lionel B



Relevant Pages

  • Re: Stable priority queue
    ... > If a 5GHz computer had an integer increment that took only one CPU cycle ... We could also use the sizeof trick though, which is a cool use of template ... struct typelist ... typedef T car; ...
    (comp.lang.cpp)
  • Re: STL::list trouble in VC6
    ... > | not compile, as sizeofcould be used in the definition ... // Provides some storage for small strings... ... template ... struct basic_string_helper ...
    (alt.comp.lang.learn.c-cpp)
  • Re: bizarre metaprogramming error
    ... > VC7.1 does not even compile it... ... > template <typename T> ... > struct assertion; ...
    (microsoft.public.vc.language)
  • curiously recurring template pattern problem
    ... typedef typename Derived::type type; ... struct Y: public X ... derived type as a template parameter to X (aka the curiously recurring ...
    (comp.lang.cpp)
  • Re: function template
    ... > I was working with a simple function template to find the min of two values. ... struct Promote ... template struct Promote{typedef unsigned long ... template struct Promote{typedef int ...
    (comp.lang.cpp)