2

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.

Community
  • 1
  • 1
Li Zhen
  • 95
  • 5

1 Answers1

4

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!

templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065