View Single Post
Old May 27th, 2006, 3:09 AM   #19
Soulstorm
Hobbyist Programmer
 
Soulstorm's Avatar
 
Join Date: Jan 2006
Location: Menidi, Athens, Greece
Posts: 243
Rep Power: 3 Soulstorm is on a distinguished road
Of course. I don't have the code in front of me, but i remember that the problem resided in the clearstash() function. When I was deleting the 'ch' pointer, I didn't make sure wether that pointer was allocated or not. The result was in some occasions the compiler to give me warnings and errors (when the 'clearstash()' function was called before a string allocation was made).

The solution was to pass the 'ch' pointer a zero value at the beginning (in my constructors), then with an 'if' statement, make sure every time I call 'clearstash()' the 'ch' pointer is allocated before deallocation. That could be done like this, if I remember correctly:

void stash::clearStash(){
	if(ch)
		delete [] ch;
	ch = new char [gIncrement];
	currentSize = 0;
	currentStorage = gIncrement;
	next =  gIncrement - currentSize;
}
...supposing we have set the 'ch' as 0 at the constructors.
__________________
Project::Soulstorm (personal homepage)

Last edited by Soulstorm; May 27th, 2006 at 3:23 AM.
Soulstorm is offline   Reply With Quote