Frage

What is the matter of the error, which produces the following code?

struct foo
{
    void call(void (foo::*ptr)()) &&
    {
        (*this.*ptr)();
    }
};

How to fix this error?

War es hilfreich?

Lösung

Since the member pointer has the rvalue qualifier, the compiler must be told that *this is to be treated as an rvalue by using std::move on it:

(std::move(*this).*ptr)();
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top