Name: Anonymous 2006-05-19 18:41
#include<iostream>
using namespace std;
struct db : public unary_function<int, int> {
int operator()(const int& x) { return 2 * x; }
};
void f(int x, unary_function<int, int> t) {
cout << t(x) << endl;
}
int main() {
f(2, db());
return 0;
}
Gives me a compile error:
test.cpp: In function ‘void f(int, std::unary_function<int, int>)’:
test.cpp:11: error: no match for call to ‘(std::unary_function<int, int>) (int&)’
using namespace std;
struct db : public unary_function<int, int> {
int operator()(const int& x) { return 2 * x; }
};
void f(int x, unary_function<int, int> t) {
cout << t(x) << endl;
}
int main() {
f(2, db());
return 0;
}
Gives me a compile error:
test.cpp: In function ‘void f(int, std::unary_function<int, int>)’:
test.cpp:11: error: no match for call to ‘(std::unary_function<int, int>) (int&)’