[function] Defect or feature?

Hello. I think this code should work (or convince me why not): #include <boost/function.hpp> class A {}; class B : public A {}; typedef boost::function<void (A &)> F; void hello(B &) { } int main() { F f(&hello); } Since A & can accept Bs &, should this code work?

AMDG Germán Diago wrote:
Hello. I think this code should work (or convince me why not):
#include <boost/function.hpp>
class A {}; class B : public A {};
typedef boost::function<void (A &)> F;
void hello(B &) { }
int main() { F f(&hello); }
Since A & can accept Bs &, should this code work?
No it shouldn't. hello takes a B&. F can take any A& even one that isn't really a B. It would work if it were the other way around: typedef boost::function<void(B&)> F; void hello(A&) {} In Christ, Steven Watanabe
participants (2)
-
Germán Diago
-
Steven Watanabe