Skip to main content
gamedev.net
🔒 Locked

Allocating memory problem

Started by bigwiger Jun 3, 2003 at 7:46 PM 0 replies 500+ views
Original Post
bigwiger
bigwiger
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?
Disgruntled designers are always the best ones
bzroom
bzroom
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]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.