I have written a class which allocates an array of unsigned chars using new, but when I create multiple instances of this class, they all point to the same block of memory. Any idea what I'm doing wrong here?
Code:
//the relevant code in the constructor //v is an unsigned char* //r and c are integers //init is an unsigned char this->v = new unsigned char[r*c]; memset(v,init,r*c);
Code:
//the code which creates the objects //water,hills and active are all an uninitialised FieldMap //gs.rows and gs.cols are integers this->water = FieldMap(gs.rows,gs.cols,255); this->hills = FieldMap(gs.rows,gs.cols,128); this->active = FieldMap(gs.rows,gs.cols,128);
Comment