![](/img/trans.png)
[英]In a non-const member function, why is point this non-const, while decltype pointer this is const?
[英]How to declare a member function const pointer while point to const address
我的意思是像const char* const p;
或char const * const p;
。 這里的p
代表指針指向const char,而指針本身也是const。 所以*p = 'a';
或char c = 'c'; p = &c;
char c = 'c'; p = &c;
不會被遵守。
請有人告訴我如何聲明一個指向成員函數的指針,該成員函數指向的對象本身就是const,帶有和不帶有typedef
。
不在實踐中只是好奇而已。
這不是我要問的。
不能取消引用成員函數指針來修改指針,因此僅需要一個const:
RetType (Class::* const ptr)(Arg1Type, ..., ArgNType) = ...;
使用typedef:
typedef RetType (Class::* PtrTypedefName)(Arg1Type, ..., ArgNType);
const PtrTypedefName ptr = ...;
希望這可以幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.