开发者

struct object declaration

hello every i have made a structure and i w开发者_C百科ant 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


If I understand well the problem, I would say that you use far too much the "struct" keyword.

If you define your struct as

struct grapharray
{
    int structcol;
    double  *structpayloadgraph;
    double  *structsessiongraph;
};

then you don't need to use the keyword "struct" when declaring the variables.

grapharray  gao;  // without struct keyword
grapharray  gao1; // without struct keyword

and your function should be

grapharray graphplotdata(char * filename) // without struct once again.
{
    // computing some values and returning structure object
}

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜