Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
689 views
in Technique[技术] by (71.8m points)

How to define a struct in c++?

I'm try to make an payroll program in c++. In the beginning of my program I have to define a struct called EmployeeT that will store all the information about an employee together in one unit.

Then I have to take all that information and put it in an array of EmployeeT structures called employees.

I have this so far...

typedef struct 
{
  char name[];
  char title;
  double gross;
  double tax;
  double net;
}  EmployeeT;

So, What am I miss or doing wrong?

Thanks guys

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

What you have there is fine, except that if you want a flexible array member (char name[]), it needs to be the last field in the structure. Probably what you really want is a pointer (char *name) or a real array (char name[SOME_SIZE]), though.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...