Re: "Function template" problem

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


Date: 30 Sep 2004 03:35:44 -0700

Gernot Frisch wrote:
> <google@lionelb.com> schrieb im Newsbeitrag
> news:1096533787.039138.214520@k26g2000oda.googlegroups.com...
> > Gernot Frisch wrote:
> >> "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);
> >
> > Apologies if I'm being obtuse, but I don't understand this reply at

> > all
> > :(
>
> er... do you know what templates are and what you use them for?

Yes.

> What are you trying to do? I don't get a clue from your source code,
> that I have in common with your compiler ;)

I am implementing Todd Veldhuizen's "Pointer-to-function as a template
parameter" scheme to inline callbacks in extensive loops. See
http://osl.iu.edu/~tveldhui/papers/techniques/ (Section 1.4) for the
rationale behind the technique.

My sample code is a "minimalist example" of the real problem which
arose when trying to build a template class (my class B above) with a
function (my function B::foo) that calls the member template function
(my A::eval) for a member object (my B::a). I hope this is clear(ish).

The (rather esoteric) solution I was looking for was supplied by Markus
Moll in a previous post.

Regards,

-- 
Lionel B


Relevant Pages

  • Re: EVC++: compile errors disappear when preprocessor output is on
    ... So, temporarily, I removed the template class, and replaced ... point, I decided I needed a templated constructor for that one though, ... also solved that one's compile errors when I used it as a member ...
    (microsoft.public.vc.language)
  • Possible g++ bug in template parsing
    ... The attached code compiles and works properly when I comment out the ... declaration, definition, and invocations of the method 'eck'. ... Note that 'gak' (a template function in a template class) works, ...
    (comp.lang.cpp)
  • Re: Curing Lycanthropy
    ... There's a reason I recommend the lycanthrope template classes from the Wizards ... take the next X levels in the template class and the animal class. ... Who do you blame when your kid is a - brat? ...
    (rec.games.frp.dnd)
  • Re: what about the template error??
    ... > template<class T,int MAXMIZE> ... at that point that the compiler knows the template parameters. ... that it knows all the details of the template class that are required. ...
    (microsoft.public.vc.stl)
  • Re: Keeping the template implementation in .C
    ... > It is necessary to compile the whole template code with the type of the ... > correct object code and can not check if the template parameter meets all ... class-independent part of your template class into another class. ...
    (comp.unix.programmer)