Boost logo

Boost Users :

Subject: Re: [Boost-users] [function] Defect or feature?
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-11-09 13:53:21


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


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net