const指针解引
来源:互联网 发布:淘宝卫龙旗舰店 编辑:程序博客网 时间:2024/06/05 11:51
引用和指针
引用和指针引用的行为像一个const指针解引用一个有趣的关系式。从而给出如下:
int nValue = 5;int *const pnValue = &nValue;int &rnValue = nValue;*pnValue and rnValue evaluate identically. As a result, the following two statements produce the same effect:*pnValue = 6;rnValue = 6;
同样,一个const引用的行为就像一个const指针指向const对象是隐式解引用。
因为引用总是“点”来有效的对象,而不能指出释放内存,引用的是比使用指针安全。如果一个任务可以通过引用或指针解决,参考一般应首选。指针通常只能用在引用是不充分的情况下(如动态分配的内存)。
成员的选择
通常有一个指针或引用一个结构(或类)。正如你已知道的,你可以选择使用一个struct的成员选择运算符成员(。):
struct Something{ int nValue; float fValue;};// Member selection using actual struct variableSomething sSomething;sSomething.nValue = 5;// Member selection using reference to structSomething &rsSomething = sSomething;rsSomething.nValue = 5;// Member selection using pointer to structSomething *psSomething = &sSomething;(*psSomething).nValue = 5;
0 0
- const指针解引
- CONST 指针
- const指针
- CONST指针
- const 指针
- const指针
- const指针
- const指针
- const指针
- const 指针
- const 指针
- const指针
- const指针
- const指针
- const指针
- const指针
- const 指针
- const 指针
- android 电容屏(二):驱动调试之基本概念篇
- 修改linux hostname
- type=image和type=submit的区别
- Eclipse快捷键大全(转载)
- AES算法Java实现浅析
- const指针解引
- 《Javascript高级教程(中文版)》(chm)计算机电子书下载
- 批量修改 wordpress 标题 和对应的 slug (post_title,post_name): sanitize_title($title);生成slug
- CF —— IQ Test
- DY2100在线代理-网站代理-网页代理
- 新浪微博开发平台接入流程(2)---SDK Demo
- dict使用详解
- 逻辑回归关于经验风险最小化的凸近似体现
- c# clickonce下载完应用程序后无法启动