User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 392,297 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,934 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:

Trying to use pointers

Join Date: May 2005
Posts: 232
Reputation: Dogtree is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 2
Dogtree's Avatar
Dogtree Dogtree is offline Offline
Posting Whiz in Training

Re: Trying to use pointers

  #9  
May 17th, 2005
Either n is bigger than 50, which is the last accessible index in your array, or you aren't allocating memory to each Activity pointer in the array. You probably want to allocate the initial memory like this:
Activity **p = new Activity*[51];

for (int i = 0; i < 51; i++)
  p[i] = new Activity;
Then you release the memory like this:
for (int i = 0; i < 51; i++)
  delete [] p[i];
delete p;
Unless you do this, you'll have to initialize each pointer to an existing object before you try to dereference it.
Reply With Quote  
All times are GMT -4. The time now is 9:40 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC