"Function template" problem

From: Lionel B (google_at_lionelb.com)
Date: 09/30/04


Date: 30 Sep 2004 00:55:04 -0700

Greetings,

I cannot figure out why the following code does not compile:

--- BEGIN CODE ---

typedef double ftype(double);

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: associative array, container, mapping, terminology
    ... |> is a pointer, I see that as a kind of type, but also specific to what it ... |> different kind of struct I consider to really be two different types. ... | but which kind isn't known at compile time, ... I'm looking at having a mapping that is homogenous keys and homogenous data, ...
    (comp.programming)
  • Re: Generating a simple hand-coded like recursive descent parser
    ... include compound words due to intrinsic functions. ... What do you mean by keyword combinations? ... "compile", directive on what compiler options will be used ... struct ASTNode { ...
    (comp.compilers)
  • Re: curiously recurring template pattern problem
    ... > struct X ... > typedef int type; ... > type is not allowed' pointing at the typedef in X. ... > this kind of construct is difficult or impossible to compile for some ...
    (comp.lang.cpp)
  • Re: Need help in Including/converting C files in C++ project
    ... I never realized that I should set the "Compile As" ... > struct X ... > differs from X in the typedef. ... The name of the first struct is X in C++, ...
    (microsoft.public.vc.language)
  • Re: ANSI C Compilation linking problem
    ... I have the files group.h and group.c that use a struct define in logic.h and two fonctions define in logic.c. ... when the program compile, it is able to find the reference to the ... So the logic.o wasnt really compile and he forgot that it wasnt complete and still tryed to link it. ...
    (comp.lang.c)