Is there a size limit on a class?

Started by
8 comments, last by smart_idiot 19 years ago
I initilized an array of integers in a class. I then made an array of a class (thus multiply arrays of that array). When the program tries to modify the array of integers it crashes. The strange thing is that it works fine until it reaches the third or fourth array value(there's 9 in all). Is there a limit on what a class can hold or is it that you can't make an array of a class that contains another array. Any help would be appreciated
Advertisement
If you're instantiating your classes on the stack and not using dynamically allocated arrays (your array of integers in said class) you may be running out of stack space.

There is no limit on what a class can hold--and yes, you may instantiate arrays of classes which have an array as a member.
As far as I know, there is no such limit either way. If it is an array of only 9 ints in the class, then how big is the array of classes(how many of the 9 int arrays?)? The only limit would be memory, in which case you would need to allocate for it using new or malloc() because each program only gets a small amount of memory in the RAM. For storing other things, big things, use new or malloc as they grab memory from the "heap" which includes all available memory on the computer and even maybe virual memory, though that is very slow(another story). Another issue is if for some reason, you are going out of bounds of the arrays. If it is an array of 9 ints and somewhere you try to access 10 or up in the array, it crashes with a general protection fault or something like that. If it isn't any of the above, post some code.

EDIT The above poster just beat me to it.


Its actually a pretty large project so i can't post any codes.
The problem is when i make the class array three members, it works. But anything over makes the program crashes when it starts working on the forth class array member. But I think you guys were on to something.

Thanks alot.
Of course there are limits.

template <int d> class foo {  foo<d-1> bar, baz; };class foo<0> {  int bar; };int main() {  foo<500> goodbye_cruel_world; }
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
is there any good tutorial out there about memory allocation?
I would suggest just going down the list. There is not one tutorial that can teach you all [wink]. Best of luck!
Quote:Original post by smart_idiot
Of course there are limits.


Ah, but which limit did you hit? Template recursion limit? Class member count limit? Stack overflow?
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Quote:Original post by Fruny
Quote:Original post by smart_idiot
Of course there are limits.


Ah, but which limit did you hit? Template recursion limit? Class member count limit? Stack overflow?


What's funny is that if he would have used 498, it would have worked fine [smile] (Visual Studio 6) In Dev CPP you would see this:
Quote:13 C:\Documents and Settings\Drew Benton\Desktop\main.cpp size of variable 'goodbye_cruel_world' is too large

I vote for the template recursion overflow.
Nope, template recursion gives a different error. The problem is that the class is 1.30935624e151 bytes in size. It branches out as a tree 500 layers deep, and each leaf has an integer.

I think GCC's template recursion limit is 512 by default. The documentation says not to rely on more than 17 in a ISO C++ compliant program though, so. . .
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.

This topic is closed to new replies.

Advertisement