小编ejk*_*koy的帖子

如何将const成员函数作为非const成员函数传递

如何将const成员函数作为非const成员函数传递给模板?

class TestA 
{
public:
    void A() {
    }

    void B() const {
    }
};

template<typename T, typename R, typename... Args>
void regFunc(R(T::*func)(Args...)) 
{}

void test() 
{
    regFunc(&TestA::A); // OK
    regFunc(&TestA::B); // ambiguous
}
Run Code Online (Sandbox Code Playgroud)

不想添加类似的内容:

void regFunc(R(T::*func)(Args...) const)
Run Code Online (Sandbox Code Playgroud)

有没有更好的办法?

c++ templates member-function-pointers class c++11

4
推荐指数
1
解决办法
130
查看次数

标签 统计

c++ ×1

c++11 ×1

class ×1

member-function-pointers ×1

templates ×1