View Single Post
Old 07-21-2002, 12:08 AM   #3 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,720
redhead is on a distinguished road
And yet, still theres something wrong with it..
you are creating an Album** with the Album* album[5];, if you wan't a static one, where you know it's gonna be 5, then use Album album[5];
Or if you wan't it to be a dynamicaly growing array, then use something like this:
Code:
int maxAlbums = 10;
int numAlbums = 0;
Album* albums;

albums = (Album*) malloc(maxAlbums * sizeof(Album));
if(!albums)
  {
    fprintf(stderr, "Not enough heap space\n");
    exit(-1);
  }
while (some_condition)
{
  if(numAlbums >= maxAlbums)
    {
       maxAlbums += 10;
       albums = (Album*)realloc(albums, maxAlbums*sizeof(Album));
        if(!albums)
          {
           fprintf(stderr,"Not enough heap space\n");
           exit(-1);
          }
      }
  albums[numAlbums++] = new Album;
}
Altho this is C, and not C++. I would guess using some kind of vector to store it in, would be the right thing to do. And then just use push and pop to extend it.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote