简体   繁体   中英

pointer-to-member-function type requires an rvalue

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?

由于成员指针具有 rvalue 限定符,因此必须告诉编译器*this将通过在其上使用std::move被视为右值:

(std::move(*this).*ptr)();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM