结构体对象声明
大家好,我已经制作了一个结构,我想用它制作 2 个对象。我正在使用 qtcreator。
我写
struct grapharray gao ;
(grapharray 是我的结构)
每个东西都运行良好,但是当我编写另一个对象(例如
struct grapharray gao ;
struct grapharray gao1 ;
我的程序意外完成)时,任何人都可以告诉我为什么会这样以及我应该在哪里声明该结构 这里的对象
struct grapharray
{
int structcol;
double *structpayloadgraph;
double *structsessiongraph;
};
是我的结构;
我有一个功能,
struct grapharray graphplotdata(char * filename)
{ // computing some values and returning structure object
}
谢谢
hello every i have made a structure and i want to make 2 objects of it . i am using qtcreator.
i write
struct grapharray gao ;
(grapharray is my structure)
every thig works well but when i write another object like
struct grapharray gao ;
struct grapharray gao1 ;
my program unexpectedly finishes can any one tell me why is it so and where should i declare the struct object
struct grapharray
{
int structcol;
double *structpayloadgraph;
double *structsessiongraph;
};
here is my structure;
and i have a function
struct grapharray graphplotdata(char * filename)
{ // computing some values and returning structure object
}
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我很好地理解这个问题,我会说你使用了太多的“struct”关键字。
如果您将结构定义为,
则在声明变量时不需要使用关键字“struct”。
并且您的函数应该是
结构,其工作方式与类几乎相同;主要区别在于,结构成员和方法默认为“公共”,类成员和方法默认为“私有”。
编辑:考虑到 Dennis Zickefoose 的评论,这不是一个好的答案。
If I understand well the problem, I would say that you use far too much the "struct" keyword.
If you define your struct as
then you don't need to use the keyword "struct" when declaring the variables.
and your function should be
structs does works almost the same way as classes; the main difference is that structs members and methods are "public" by default and classes members and methods are "private" by default.
Edit: Considering the comment of Dennis Zickefoose, this is not the good answer.