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

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++中可以这样定义变量吗?
恕我无知,以前从没见过……

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。
改正下面C#的代码错误public partial class Form7 : Form { private BigInteger p, q, n, phi_n, e, d; public Form7() { InitializeComponent(); } private void Form7_Load(object sender, EventArgs e) { GenerateKeys(); } private void GenerateKeys() { // 选择两个质数p和q string string1, string2; Int64 n, p, q, phi_n, e; p = BigInteger.Parse("12347534159895123"); q = BigInteger.Parse( "987654321357159852"); n = p * q; phi_n = (p - 1) * (q - 1); // 选择e并计算d e = 65537; d = ModInverse(e, phi_n); publicKeyTextBox.Text = $"{n} {e}"; privateKeyTextBox.Text = $"{n} {d}"; } private BigInteger ModInverse(BigInteger e, long phi_n) { throw new NotImplementedException(); } // 加密函数 private string Encrypt(string message, BigInteger n, BigInteger e) { BigInteger m = StrToBig(message); BigInteger c = BigInteger.ModPow(m, e, n); return BigToStr(c); } // 解密函数 private string Decrypt(string ctext, BigInteger n, BigInteger d) { BigInteger c = StrToBig(ctext); BigInteger m = BigInteger.ModPow(c, d, n); return BigToStr(m); } // 字符串转换为大整数 private BigInteger StrToBig(string str) { byte[] bytes = System.Text.Encoding.Unicode.GetBytes(str); return new BigInteger(bytes); } // 大整数转换为字符串 private string BigToStr(BigInteger big) { byte[] bytes = big.ToByteArray(); return System.Text.Encoding.Unicode.GetString(bytes); } // 计算模反元素 private BigInteger ModInverse(BigInteger a, BigInteger m) { BigInteger x, y; ExtendedGCD(a, m, out x, out y); return x; } // 扩展欧几里得算法 private void ExtendedGCD(BigInteger a, BigInteger b, out BigInteger x, out BigInteger y) { if (b == 0) { x = 1; y = 0; } else { ExtendedGCD(b, a % b, out y, out x); y -= a / b * x; } } private void encryptButton_Click(object sender, EventArgs e) { string message = inputTextBox.Text; string ctext = Encrypt(message, n, e); outputTextBox.Text = ctext; } private void decryptButton_Click(object sender, EventArgs e) { string ctext = outputTextBox.Text; string message = Decrypt(ctext, n, d); outputTextBox.Text = message; } } }
06-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值