E
eefacm
I've been experimenting with Boost.Function. I wrote a little test
program, of which this is the guts:
template <typename T>
void call_with_arg(function<void (T)> func, T arg) {
func(arg);
}
void print_it(int x) {
cout << "printit: " << x << endl;
}
int main() {
call_with_arg(print_it, 1);
}
When I compile this with g++ 4.0.1, I get this error:
a.cc: In function 'int main()':
a.cc:24: error: no matching function for call to 'call_with_arg(void
(&)(int), int)'
I can't figure out why. It works if I say:
call_with_arg<int>(print_it, 1);
Or:
function<void (int)> func = print_it;
call_with_arg(func, 1);
So why doesn't the first way work?
program, of which this is the guts:
template <typename T>
void call_with_arg(function<void (T)> func, T arg) {
func(arg);
}
void print_it(int x) {
cout << "printit: " << x << endl;
}
int main() {
call_with_arg(print_it, 1);
}
When I compile this with g++ 4.0.1, I get this error:
a.cc: In function 'int main()':
a.cc:24: error: no matching function for call to 'call_with_arg(void
(&)(int), int)'
I can't figure out why. It works if I say:
call_with_arg<int>(print_it, 1);
Or:
function<void (int)> func = print_it;
call_with_arg(func, 1);
So why doesn't the first way work?