Re: Template function as argument to another template function
From: Nicolas Pavlidis (pavnic_at_sbox.tugraz.at)
Date: 10/07/04
- Next message: Howard: "Re: How to create a bitmap?"
- Previous message: Howard: "Re: C++ 2003"
- In reply to: Nicolas Pavlidis: "Re: Template function as argument to another template function"
- Next in thread: Jim West: "Re: Template function as argument to another template function"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 07 Oct 2004 19:38:57 +0200
Nicolas Pavlidis <pavnic@sbox.tugraz.at> writes:
> Jim West <eggplantparts@yahoo.com> writes:
>
> > The following code compiles and executes properly on one compiler
> > (GNU C++) but not on another (Intel C++ V8.1). Which compiler is
> > correct? If my code is improper (that is, the Intel compiler is
> > correct), is there an appropriate way to do what I'm trying to do?
> >
> >
> > template <class T>
> > T FOO(const T &a) { return a; }
> >
> > template <class T>
> > T BAR(T (*f)(const T &b), const T &c) { return f(c); }
> >
> > int main() {
> > double x = 10.0;
> > double y = BAR(FOO, x);
> > }
>
> IMHO intel is "more correct", you want to call BAR this way:
>
> double y = BAR(FOO<double>, x);
>
> Then intel will must not make any problems.
>
> As you see intel needs a real instantiation of the templated function,
> maybe g++ finds the correct type by itself.
g++ is a bit more inteligent :-). It makes the folowing (I think that it
soes after analysing your code) :
The jole is that every instantiation of foo may fit the requirement for
the functionpoiunter in the paramlist for bar, so this is no problem for
g++, the real instatiation of foo is generated while instatiating bar in
main().
intel needs a real function for passing a functionpointer, so the
exlpicit instantiation is necessary, which is a problem for the MSVC -
compilers :-).
Kind regrads,
Nicolas
-- | Nicolas Pavlidis | Elvis Presly: |\ |__ | | Student of SE & KM | "Into the goto" | \|__| | | pavnic@sbox.tugraz.at | ICQ #320057056 | | |-------------------University of Technology, Graz----------------|
- Next message: Howard: "Re: How to create a bitmap?"
- Previous message: Howard: "Re: C++ 2003"
- In reply to: Nicolas Pavlidis: "Re: Template function as argument to another template function"
- Next in thread: Jim West: "Re: Template function as argument to another template function"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|