$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
Subject: [boost] [bind] virtual function pointer woes
From: Eric Niebler (eric_at_[hidden])
Date: 2009-01-08 14:19:04
Imagine I have a base class B with a virtual function f() that is
overridden in a derived class D ...
struct B { virtual void f() { std::printf("B\n"); } };
struct D : B { virtual void f() { std::printf("D\n"); } };
Now, I can have a derived object D and call the base member directly
using qualification:
D d;
d.B::f(); // OK, called B::f
But if I take the address of B::f for use with boost::bind, I get a
thunk that always uses virtual dispatch...
boost::bind( &B::f, _1 )( d ); // Hrm, calls D::f
What if I don't want the virtual dispatch, and I really want this to
behave like d.B::f()?
I know this is not specifically a problem with boost::bind, but a more
general property of (virtual) member function pointers. Is there any way
to get a non-virtual member function pointer to a virtual member
function? If there is a way, I'm sure I don't know it.
-- Eric Niebler BoostPro Computing http://www.boostpro.com