我正在尝试使用boost::bind
调用类中的成员函数。通常这可以正常工作,但在这种特殊情况下,我的编译器 (GCC) 抱怨我在尝试使用不可访问的基类,而我不是。
这是一些演示问题的代码。我究竟做错了什么?
#include <iostream>
#include <boost/bind.hpp>
#include <boost/function.hpp>
class base
{
protected:
void test()
{
std::cout << "base::test()\n";
}
};
class derived: virtual protected base
{
public:
using base::test;
};
int main(void)
{
derived d;
// This works, calling derived::test(), which in turn calls base::test()
d.test();
// This does not work, saying 'base' is an inaccessible base of 'derived',
// but I am not binding base::test, I am binding derived::test.
boost::function<void()> fn;
fn = boost::bind(&derived::test, d);
fn();
return 0;
}