View Single Post
Old 08-04-2002, 11:44 AM   #5 (permalink)
sdeming
Code Monkey
 
Join Date: Jul 2002
Location: Michigan
Posts: 85
sdeming is on a distinguished road
Kinda late in the game here, but I'll reply anyway...
Quote:
int main()
{
int const CAPACITY=5;
Album* data[CAPACITY];


for(int count=0;count<CAPACITY;count++)
{
data[count]= new Album;
data[count]= 0;
}



return 0;
}
There is a memory leak here. When you say data[count] = 0, the reference to the recently allocated Album is lost forever. However, what Redhead says is absolutely right. If you are using C++ you never have to deal with Arrays in this sense again, consider the following:
Quote:
#include <vector>
class Album { ; } // <-- implement this
int main() {
int const CAPACITY=5;
std::vector<Album*> albums;

for (int count=0; count<CAPACITY;count++) {
albums.push_back(new Album);
}
}
Now you have 5 freshly allocated Album objects, ready for use. To access albums, treat it just like an array:
Quote:
album[4]->displaySongList();
(or whatever methods are available).
__________________
Scott
B4 09 BA 09 01 CD 21 CD 20 53 63 6F 74 74 24
sdeming is offline   Reply With Quote