lundi 3 décembre 2018

How to pass const member function as non-const member function

How to pass a const member function as a non-const member function to the template?

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
}

Don't want to add something like:

void regFunc(R(T::*func)(Args...) const)

Is there a better way?

Aucun commentaire:

Enregistrer un commentaire