P
PengYu.UT
Hi,
I couldn't see what is wrong with the following program. Would you
please help me?
Thanks,
Peng
g++-3.4 -MM -g main.cc > .dep
g++-3.4 -g -c -o main.o main.cc
main.cc: In function `int main()':
main.cc:26: error: cannot convert `double' to `function<int> (*)()' for
argument `1' to `const interpolator2d<function<int> >
inter_f(function<int> (*)())'
make: *** [main.o] Error 1
#include <functional>
template <typename F>
class interpolator2d {
public:
interpolator2d(const F &f) : _f(f) {
}
typename F::result_type operator()(double x, double y) const {
return _f(x, y);
}
private:
F _f;
};
template <typename T>
struct function : public std::binary_function<T, T, double> {
double operator()(T x, T y) const {
return - (x * x + y * y);
}
};
int main() {
const interpolator2d<function<int> > inter_f(function<int>());
double x = 0;
double y = 0;
inter_f(1.1, 1.1);
}
I couldn't see what is wrong with the following program. Would you
please help me?
Thanks,
Peng
g++-3.4 -MM -g main.cc > .dep
g++-3.4 -g -c -o main.o main.cc
main.cc: In function `int main()':
main.cc:26: error: cannot convert `double' to `function<int> (*)()' for
argument `1' to `const interpolator2d<function<int> >
inter_f(function<int> (*)())'
make: *** [main.o] Error 1
#include <functional>
template <typename F>
class interpolator2d {
public:
interpolator2d(const F &f) : _f(f) {
}
typename F::result_type operator()(double x, double y) const {
return _f(x, y);
}
private:
F _f;
};
template <typename T>
struct function : public std::binary_function<T, T, double> {
double operator()(T x, T y) const {
return - (x * x + y * y);
}
};
int main() {
const interpolator2d<function<int> > inter_f(function<int>());
double x = 0;
double y = 0;
inter_f(1.1, 1.1);
}