问题
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:
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!
来源:https://stackoverflow.com/questions/20699916/how-to-declare-a-member-function-const-pointer-while-point-to-const-address