在 http://topic.csdn.net/u/20071203/19/47c033a5-6501-49c1-ac1b-ead5cadb0fca.html?seed=50094126
看到
include   <iostream>
using       namespace       std;
class       CText
{
public:        
                        const       int       a;
                        CText();
};
CText::CText():a(0)
{
         
}
int       main()
{
            CText       t;        
            int       const       CText::*p;
            p=&CText::a;
            int       CText::*q;
            q=(int       CText::*)p;
            t.*q=10;
            cout   <   <t.*q   <   <endl;
            return       0;
}
这样的程序,不明白
                        CText               t;                
                        int               const               CText::*p;
                        p=&CText::a;    
是什么意思?C++中可以这样定义变量吗?
恕我无知,以前从没见过……

  • jxlczjp77  回复道:

int       const       CText::*       p       定义了类CText的成员变量指针,其中这个成员变量为const       int       类型。

总的来说p其实代表的就是一个偏移量  
p=&CText::a;       //在类CText中把变量a的偏移量给p

现在通过变量p就可以直接操作某一个CText对象的成员变量a。  
CText       t;  
t.*p       =       10;       //.*操作符,相当于t.a       =       10

CText       *pt       =       &t;  
pt->   *p       =       10;       //->   *操作符,也相当于t.a       =       10

x谢谢jxlczjp77。

class CText{}; CText t; int const CText::*p; 什么意思?相关推荐

  1. const int * 、int * const、int const* 、const int a(){ } 和int a()const { }的区别和联系

    前言:很多人都把const int * .int * const.int const* 的区别和联系搞混,我自己在学习C++的过程中,也经常性          弄不 清楚,今天特意总结一下,作为学习 ...

  2. 喜闻乐见的const int *p、int* const p、const int* const p

    不废话直接代码示例: 1 void f(const int *p) { 2 3 int b = 10; 4 5 *p = 10; // error 6 7 p = &b; // fine 8 ...

  3. 2020-09-21C++学习笔记之与C语言区别和加强——四种const意义(const int a; int const b; const int *c; int * const d)

    2020-09-21C++学习笔记(const int a; int const b; const int *c; int * const d) 这两天在上课更新晚了. 1.C/C++中的const ...

  4. int * const a, 和 const int* a,const PInt a;

    纳闷的是: const PINT a竟然 不是 const int* a; 而是: int * const a;

  5. const int *,const int * const和int const *有什么区别?

    我总是搞砸了如何正确使用<code>const int* , const int * const和int const * . 是否有一组规则定义您可以做什么和不能做什么? 我想知道在分配, ...

  6. const int 和INT const区别

    const int 和INT const区别 2010-04-09 23:26 const int a = 5; int const b = 6; 没区别 指针的时候有区别,引用也有区别 指针的话 1 ...

  7. const int、const int *、int *cosnt、const int * const、const int 的区别

    2018-01-04 创建人:Ruo_Xiao 2018-10-17 修改人:Ruo_Xiao 邮箱:xclsoftware@163.com 修改内容:增加对 delete 指向常量的指针的可行性的说 ...

  8. int *p,cons int *p,int const *p,int * const p,const int * const p,int const * const p的区别

     加有const关键字的几种情况的辨析 const修饰的代码 含义(特点) 等价性 int *p = # 1.       可以读自己 2.       可以通过*p改自己 3.       可以 ...

  9. const int *a和int*const a 的区别详解

    补充知识 "const int i"与"int const i"之间的区别 对变量来说,const 关键字可以限定一个变量的值不允许改变,从而保护被修饰的东西, ...

  10. 【转】const int *p和int * const p的区别(常量指针与指向常量的指针)

    [转]作者:xwdreamer   出处:http://www.cnblogs.com/xwdreamer 对于指针和常量,有以下三种形式都是正确的: const char * myPtr = &am ...

最新文章

  1. linux改英语环境,CentOS6.8中/英文环境切换教程图解
  2. python自定义函数详解_python基础教程之自定义函数介绍
  3. Android phone xp 华为3x,3000mAh大电池 华为荣耀3X续航能力实测
  4. 索引unusable|disable|enable
  5. 深入探究Python中的字典容器
  6. [改善Java代码]减少HashMap中元素的数量
  7. AOM Summit:拥抱开源,引领新技术创新
  8. 微信开发 网页授权获取用户基本信息
  9. 【LuoguP3241】[HNOI2015] 开店
  10. Facebook全球宕机6小时!小扎损失60亿,15亿用户数据被出售
  11. 全站仪坐标计算机公式,全站仪使用方法及坐标计算讲解
  12. 【NOIP1999】【Luogu1015】回文数(高精度,模拟)
  13. python多线程与多进程
  14. CDH安装过程中出现:主机 cdh04 上的内存被调拨过度。总内存分配额是 4.0 艾字节 个字节,但是 RAM 只有 62.8 吉字节 个字节(其中的 12.6 吉字节 个字节是保留给系统使用的)。
  15. hdoj-2567 寻梦
  16. OpenNLP 命令行
  17. rdkit 化学反应ReactionFromSmarts
  18. js打印去除页眉页脚
  19. MenuetOS, FreeDOS 有了新的发行
  20. wps中的word中公式复制完后是图片

热门文章

  1. matlab生成手机app,matlab使用App designer生成可独立运行的app
  2. 笔记本键盘有几个键失灵了怎么办?
  3. linux开机启动rsync,rsync 开机自动启动
  4. [webpack] Content not from webpack is served from “xxxx“ 并且 http://localhost:8080/ 数据为空解决方案
  5. go——垃圾回收机制(GC)
  6. python怎么修改列名_PYTHON:更改列名
  7. VS code安装GitLens提示GitLenswas unable to find Git. Please make sure Git is installed...报错
  8. CVPR 2020 | 旷视研究院提出优化领域自适应物体检测性能的类别正则化框架
  9. 字符替换 英文字符串单词个数统计 python123题解
  10. 开新林哲自曝:打造二手车全球经营