boost::reference_wrapper & polymorphism
Does boost::reference_wrapper provide polymorphic behavior? For example, if I have a boost::reference_wrapper to a base type, and I assign a derived type to it, will the function calls be polymorphic?
No.
By the way, I would be interested to know the rationale for such a strange
behavior. If anyone knows something about that...
2008/8/27 Robert Dailey
Does boost::reference_wrapper provide polymorphic behavior? For example, if I have a boost::reference_wrapper to a base type, and I assign a derived type to it, will the function calls be polymorphic? _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Oups, sorry but I misunderstood your question.
Yes, for such a case like this one:
Derived& derived=...
boost::reference_wrapper<Base> reference(derived);
reference.get().function();
the call to function() will be polymorphic.
What is not possible with boost::reference_wrapper is this:
boost::reference_wrapper<Derived> derived(...)
boost::reference_wrapper<Base> base = derived
(and this what I does not understand in the conception of this class)
2008/8/28 Nicolas Vanhoren
No.
By the way, I would be interested to know the rationale for such a strange behavior. If anyone knows something about that...
2008/8/27 Robert Dailey
Does boost::reference_wrapper provide polymorphic behavior? For
example, if I have a boost::reference_wrapper to a base type, and I assign a derived type to it, will the function calls be polymorphic? _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On Thu, Aug 28, 2008 at 1:00 PM, Nicolas Vanhoren
Oups, sorry but I misunderstood your question.
Yes, for such a case like this one:
Derived& derived=... boost::reference_wrapper<Base> reference(derived); reference.get().function();
the call to function() will be polymorphic.
What is not possible with boost::reference_wrapper is this:
boost::reference_wrapper<Derived> derived(...) boost::reference_wrapper<Base> base = derived
(and this what I does not understand in the conception of this class)
2008/8/28 Nicolas Vanhoren
No.
By the way, I would be interested to know the rationale for such a strange behavior. If anyone knows something about that...
2008/8/27 Robert Dailey
Does boost::reference_wrapper provide polymorphic behavior? For example, if I have a boost::reference_wrapper to a base type, and I assign a derived type to it, will the function calls be polymorphic?
Thank you, this is exactly what I wanted to know.
participants (2)
-
Nicolas Vanhoren
-
Robert Dailey