How to declare a member function const pointer whi

2019-08-12 05:52发布

What I mean is something like const char* const p; or char const * const p;. The p here stand for a pointer points to a const char while the pointer itself is also const. So *p = 'a'; or char c = 'c'; p = &c; won't be complied.

Please someone tell me how to declare a pointer points to a member function, both what it points to and itself is const, with and without typedef.

Not use in practice just curious about.

This is not what I'm asking about.

1条回答
在下西门庆
2楼-- · 2019-08-12 06:43

Member function pointers can't be dereferenced to modify the pointee, so only one const is needed:

RetType (Class::* const ptr)(Arg1Type, ..., ArgNType) = ...;

With typedefs:

typedef RetType (Class::* PtrTypedefName)(Arg1Type, ..., ArgNType);
const PtrTypedefName ptr = ...;

Hope this helps!

查看更多
登录 后发表回答