C / C ++结构行为 [英] C/C++ Structure behavior

查看:91
本文介绍了C / C ++结构行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello C / C ++ Guru:







我对行为有一个小问题结构,我已经声明了一个包含10个组件的结构。结构中的一些组件已经具有它们的价值但是当我使用函数DLL函数中的结构组件时,我之前设置的那些值已被删除或为空。我不知道有什么问题...别人可以帮帮我







问候,

Byze

Hello C/C++ Guru:



I have a small questions in the behavior of Structure, I have declare a structure with 10 components. Some of the components in the structure has already their value but when I use

the structure components in a function DLL function those value I set previously has been deleted or empty. I don't know what is the problem... can someone else out there help me



Regards,
Byze

推荐答案

你的结构有一些可以有随机值的内存。 (这种行为在C !!!中没有定义)。因此,您最好使用适当的struct值初始化所有组件。



考虑使用带有组件的类,这样就可以部署一个有用的构造函数,析构函数和一些功能。
your structure has some memory which can have random values. (That behavior isnt defined in C!!!). So you better initialize all components with proper values of your struct.

Consider using a class with its components, so you can deploy a useful constructor, destructor and some functionality.


回答这些问题然后看看会发生什么:



- 为什么要为本地指针指定一个void指针然后立即写入它?



- 为什么你有两个同名的结构成员?



- 你为什么要访问结构的成员(cbOrderVersion)是否存在于结构定义中?



我很惊讶甚至编译了TBH。
Answer these questions then see what happens:

- Why are you assigning a void pointer to your local pointer then immediately writing over it?

- why have you two structure members with the same name?

- why are you accessing a member of the structure (cbOrderVersion) that doesn't exist in the structure definition?

I'm surprised that lot even compiles TBH.


这篇关于C / C ++结构行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆