I want to use std::bind and make a non-virtual call to a base class function, for example: derived_obj.BaseClass::foo()
Example:
Say I have a base class A and a derived class B. A has a virtual function foo() , which is overridden by B.
class A { public: virtual void foo() { std::cout << "Hello from A::foo()!";} } class B : public A { public: void foo() overide { std::cout << "Hello from B::foo()!";} }
If I want to call A::foo() from an object of class B , I make a non-virtual call:
B b_obj; b_obj.A::foo();
Now I want to use std::bind and make a non-virtual call A::foo() from b_obj, how to do this?
I already tried casting b_obj to A and used the address &A::foo() , but no luck.
auto f = std::bind(&A::foo, static_cast<A*>(&b_obj)); f();
c ++
Allin
source share