小编And*_*son的帖子

绑定到私有继承的成员函数

我想std::bind从一个私有基类的成员函数using,在派生类中使用-declaration "public" .调用函数直接工作,但似乎绑定或使用成员函数指针不编译:

#include <functional>

struct Base {
    void foo() { }
};

struct Derived : private Base { 
    using Base::foo;            
};

int main(int, char **)
{
    Derived d;

    // call member function directly:
    // compiles fine
    d.foo();

    // call function object bound to member function:
    // no matching function for call to object of type '__bind<void (Base::*)(), Derived &>'
    std::bind(&Derived::foo, d)();

    // call via pointer to member function:
    // cannot cast 'Derived' to its private …
Run Code Online (Sandbox Code Playgroud)

c++ private-inheritance stdbind

6
推荐指数
1
解决办法
356
查看次数

标签 统计

c++ ×1

private-inheritance ×1

stdbind ×1