array too large?

D

Developwebsites

const int MAX=999;

class person {
protected:
char firstname[MAX][MAX],
lastname[MAX][MAX];
int ID[MAX];

public:
person();
};

I get an array size too large error.
Is 999x999 array too large or is a single 999 array too large?
 
C

Christoph Rabel

Hi!
const int MAX=999;

class person {
protected:
char firstname[MAX][MAX],
lastname[MAX][MAX];

Why do you need such a big 2 dimensional array for
firstname? Looks weird to me.
int ID[MAX];

public:
person();
};

I get an array size too large error.
Is 999x999 array too large or is a single 999 array too large?

Most Compilers set a limit to the size of arrays on the
stack. About 1 Million byte is probably too much...

Your class design looks very weird to me. I think you are
wasting a lot of memory.

So: Dont use a buildin array, use std::vector!

class person {
protected:
vector<string> firstname;
vector<string> lastname;
vector <int> ID;

public:
person();
};

Im not quite sure why a person should have more then one
lastname, but maybe I misunderstand your intention.

Or maybe you want to create an array of several persons.
In this case I would do it about this way:

class Person {
std::string firstname;
std::string firstname;
int id;
public:
// Some methods here

};

class Persons {
vector<Person> persons;
// Some methods here
};

hth,

Christoph
 
H

Hendrik Belitz

Developwebsites said:
const int MAX=999;

class person {
protected:
char firstname[MAX][MAX],
lastname[MAX][MAX];
int ID[MAX];

public:
person();
};

I get an array size too large error.
Is 999x999 array too large or is a single 999 array too large?

Maybe you could tell me which OS and Compiler you are using? I'm working on
arrays that are much larger and got no "array too large" error so far.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top