Archived

This topic is now archived and is closed to further replies.

Allocating memory problem

This topic is 5305 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok - I have a special structure in my program which holds an array of chars. I then have a class that has one of these structs, and when the class is initialized, so is the array of chars. When I debug the program, the char array in the structure is allocated, and does acutally store values to it, but then when I try to use the structures array, it crashes because it can''t find a value in the array, even though it has been allocated. Anyone know what the problem could be?

Share this post


Link to post
Share on other sites
Code?

edit:
Struct with array in class.


struct sChars
{
char *array;
sChars(){array = new char[5];}
~sChars(){delete[] array;}
};

class cMyclass
{
public:
sChars *myarray;

cMyclass(){myarray = new sChars();}
~cMyclass(){delete myarray;}
};



[edited by - honayboyz on June 3, 2003 8:55:46 PM]

Share this post


Link to post
Share on other sites