C++: Binding to a base class
- by Helltone
The following code works, but I'm not sure it is correct/portable.
#include <iostream>
#include <tr1/functional>
class base {
public:
base(int v) : x(v)
{}
protected:
int x;
};
class derived : public base {
public:
bool test() {
return (x == 42);
}
};
int main(int argc, char* argv[]) {
base b(42);
if(std::tr1::bind((bool (base::*)()) &derived::test, b)()) {
std::cout << "ok\n";
}
return 0;
}