GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 26-Jan-2005, 18:59
swayp swayp is offline
New Member
 
Join Date: Jan 2005
Posts: 25
swayp is on a distinguished road

Dynamic Arrays


Ok back to the questions

I've created a database of CD's in which the Database class is simply an array of pointers to CD's (another class). I've initialized it as such:

Code:
CD* databaseArray[50];

Now my question is how I can replace that 50 with a number that can change. For instance, make an array the size of the CD's in the database. Because once I have 50 CD's in the Database it will simply just start writing over them.

Anyone got any ideas?
  #2  
Old 26-Jan-2005, 21:40
Max Payne's Avatar
Max Payne Max Payne is offline
Regular Member
 
Join Date: Apr 2004
Location: 3° 08 North 101° 42 East
Posts: 332
Max Payne is a jewel in the roughMax Payne is a jewel in the roughMax Payne is a jewel in the rough
CPP / C++ / C Code:
void DynamicArray(int size)
{
  int *array = new int[size]; 
  
  // delete it
  delete[] array;
}

this way you can create an array of size detrmined during runtime, but be careful if you need to change the size, delete it first then create a new one with the same size.
__________________
When you say "I wrote a program that crashed Windows," people just stare at you blankly and say "Hey, I got those with the system, for free." Linus Torvalds
  #3  
Old 27-Jan-2005, 00:24
LuciWiz's Avatar
LuciWiz LuciWiz is offline
Moderator
 
Join Date: Jul 2004
Location: Cluj-Napoca (Romania)
Posts: 893
LuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the rough
Quote:
Originally Posted by swayp
Ok back to the questions

I've created a database of CD's in which the Database class is simply an array of pointers to CD's (another class). I've initialized it as such:

Code:
CD* databaseArray[50];

Now my question is how I can replace that 50 with a number that can change. For instance, make an array the size of the CD's in the database. Because once I have 50 CD's in the Database it will simply just start writing over them.

Anyone got any ideas?

You could also use the STL containers - like std::vector. It is resizable, while the c++ array lacks this capability.

Best regards,
Lucian
__________________
Please read these Guidelines before posting on the forum

"A person who never made a mistake never tried anything new."
Einstein
 
 

Recent GIDBlogObservations of Iraq by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
problem reading to a dynamic array noamfrie C Programming Language 9 02-Jan-2005 18:35
Knight tour (arrays help needed) dilmv C++ Forum 7 18-Oct-2004 14:31
problems with 2d arrays.. mgdpetter C Programming Language 12 27-May-2004 20:45
need help with passing 3 arrays into a function tommy69 C Programming Language 14 07-Apr-2004 00:22
Problem multiplying arrays hellhammer C Programming Language 9 29-Mar-2004 15:32

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 05:09.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.