如何获取指向 memcpy 成员变量的指针
编辑以澄清; 为什么这个还不能编译?
class Member{
public:
__int32 PublicInt;
}
Member x;
memcpy(&x.PublicInt,&ByteArray,sizeof(__int32));
这不是得到一个指向 int 存储位置的指针吗?
edited for clarification;
why wont this work yet compile?
class Member{
public:
__int32 PublicInt;
}
Member x;
memcpy(&x.PublicInt,&ByteArray,sizeof(__int32));
is this not getting a pointer to the place where int is stored?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果你的变量是
...那么它的地址是:
请注意,通过数组引用得到的是地址,所以如果
ByteArray
确实是一个字节数组,我怀疑您刚刚在您的memcpy
中放错了&
,这就是您想要的:我还建议这样做:
...以防您更改其类型之后。
If your variable is
...then its address is:
Note that what you get with an array reference is the address, so if
ByteArray
is really a byte array, I suspect you've just misplaced the&
in yourmemcpy
and that this is what you want:I'd also recommend doing this:
...in case you change its type later.
这是一个快速示例来帮助您理解:
Hth :)
Here is a quick sample to help you understand:
Hth :)