Boost logo

Boost :

Subject: Re: [boost] [bind] virtual function pointer woes
From: Chris (indy271828_at_[hidden])
Date: 2009-01-08 14:26:37

As far as I know, no. If you find a true answer, please tell me.
I had this problem once as well and looked into it on the newsgroups.
There may be a non-portable way with the vtable and asm, but not
generally. My suggestion would be to make a split

_nv function that does the call

struct B { virtual void f() { f_nv(); } void f_nv()
{std::printf("B\n"); } };
struct D : B { virtual void f() { f_nv(); } void f_nv() {
std::printf("D\n"); } };

And then bind _nv;

Eric Niebler wrote:
> 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.

Boost list run by bdawes at, gregod at, cpdaniel at, john at