SPMP
SPMP

Reputation: 1223

Pointer to const overloaded member function

I have a class with const-overloaded accessor methods to a member. These accessors are declared using decltype, and it's a convention that my colleagues follow. Now, I need to create a pointer to the const version of the accessor function. I am trying to use result_of to do that, but I haven't had any success. Could someone help?

#include<type_traits>

class A{
    int _member;
    public:
    const decltype(_member) &member() const;
    decltype(_member) &member();    
};

std::result_of<static_cast<const A *>(nullptr)->member()>::type (A::*fnPtr)() const = &A::member;

Upvotes: 2

Views: 712

Answers (1)

T.C.
T.C.

Reputation: 137315

decltype(std::declval<const A&>().member()) (A::*fnPtr)() const = &A::member;

Upvotes: 6

Related Questions