如何在指向const地址时声明成员函数const指针

编程入门 行业动态 更新时间:2024-10-20 20:30:58
本文介绍了如何在指向const地址时声明成员函数const指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的意思是类似const char* const p;或char const * const p;的东西.此处的p表示指针指向const char,而指针本身也是const. 因此,不会遵守*p = 'a';或char c = 'c'; p = &c;.

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.

请有人告诉我如何声明一个指向成员函数的指针,该成员函数指向的对象本身就是const,带有和不带有typedef.

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.

这不是什么我在问.

推荐答案

不能取消引用成员函数指针来修改指针,因此只需要一个const:

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

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

使用typedefs:

With typedefs:

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

希望这会有所帮助!

更多推荐

如何在指向const地址时声明成员函数const指针

本文发布于:2023-07-29 00:45:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1235672.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:指针   函数   声明   成员   地址

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!