By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,512 Members | 3,847 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,512 IT Pros & Developers. It's quick & easy.

array too large?

P: n/a
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?

--------------------------------------------------
*** E-mail is shut off ***
--------------------------------------------------
Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi!

Developwebsites wrote:
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
Jul 22 '05 #2

P: n/a
Developwebsites wrote:
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.

--
Dipl.-Inform. Hendrik Belitz
Central Laboratory of Electronics
Research Center Juelich
Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.