making an array with a struct

i have created a certain struct and i want to create 8 instance of it as an array.

struct Account
{
int accNo;
char* name;
double balance;
double limit;
};


And following is the method i tried to create the instances

Account acc [8];

i'm getting compile errors. can someone please help.
What are the compiler errors?
you got errors?

1
2
3
4
5
6
7
8
9
10
11
12
13
[code]

struct Account
{
     int accNo;
     char* name; 
     double balance;
     double limit;
};

Account acc[8]; // this will create 8 instances of Account.
Account acc [8];  // this will generate the error.
[/code]

@Azagaros

If I understand correctly the point your trying to get at with the sample code above, White space between the variable name and brackets shouldn't do anything. It compiles for me at least.

EDIT: Could be compiler specific though.
Last edited on
it works. thanks !
Could be compiler specific though.

A compiler that complains about excessive white space is buggy. Account acc [8]; should by no means cause errors during compilation time.
Last edited on
OP posts code and says he gets an error.

Azagaros posts the exact same code.

OP replies and says it works.


I wonder what the problem was.
Actually I cut and paste it from his message.

From what I understand of c and c++ documentation: Account acc [8]; and Account acc[8] are two different things to compilers. Especially the ones that trying to reach the modern standards of c++ since [] has several meanings by itself in c++ now.
Last edited on
Topic archived. No new replies allowed.