Thursday, November 19, 2009

Progress on Assign2

I encountered several several problems in Assignment2 so far.

was creating the project skeleton and understanding that pure virtual functions of IO_Field require child classes to create and implement each function. So in a sense you ensure children are using the current most relevant function at the time. These pure virtual functions are identified as:

randomFunctionName(int randomArgument) = 0;

I was having trouble deleting IO_Label::_data. _data is a void* within IO_Field which label inherits. So to my understanding a label always contains a field with or without data in it.

I haven't got to the problem yet. So I decided to copy strings passed to new labels into _data. Of course _data had to also be casted as a char* ! So that being said the label constructors would equal _data of its parent with str via:

(char*)this->_data = str; //or something to that effect

with the hopes it would call the overloaded operator= in label, then calling set which would simply strcpy str into a char* casted _data (because its a void pointer). This is where the problem was born.

the label operator= requires a label OBJECT as its left hand argument. So my call did not give any errors but at the same time it negated the overloaded operator=, because it simply assigned _data whatever str was. Which at the time is exactly what you need.

However as the constructor went out of scope str is destroyed and by extension the data that _data pointed to because you assigned to the same thing str. Then delete[] ing _data when label goes out of scope blew up, because you can't delete something that has already been deleted.

So that problem plagued me until I finally debugged and step from the CREATION of label to see the assignment of _data fail rather then step through the DELETION of label where I thought the problem existed.

so the proper call of operator= is and should have been

*this = str;

easy mistake, big headache.

My current problem is that i'm having a brain fart as to how to get IO_Field getOwnerTop and the rest of the optional functions working. I can't wrap my head around how to access the members of io_form(its parent io_frames top, left etc) from the IO_Form* _owner. member variable in io_field.

No comments:

Post a Comment