J
Jim West
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);
}
The Intel compiler gives
$ icc simple.cc
asdf.cc(9): error: no instance of function template "BAR" matches the
argument list
argument types are: (<unknown-type>, double)
double y = BAR(FOO, x);
^
compilation aborted for simple.cc (code 2)
$
(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);
}
The Intel compiler gives
$ icc simple.cc
asdf.cc(9): error: no instance of function template "BAR" matches the
argument list
argument types are: (<unknown-type>, double)
double y = BAR(FOO, x);
^
compilation aborted for simple.cc (code 2)
$