Saturday, March 20, 2010

Virtual Muddles My Mind

Alright, so small dilemma... I have to declare an instance of another class (BField) in my class (BForm)'s constructor, this would all be well and fine if it weren't for virtual. In BField's constructor (it has no empty constructor mind you), there is something that references (void* data = (void*) 0) to be passed in. This is reference to a virtual member of BField's class (virtual void* data()). So, when I try to add something in to that position from BForm with my BField member, I get error C2259: 'BField' : cannot instantiate abstract class. Or rather, I assume this is what causes it.
So instead of this:
BField* _fld[MAX_NO_FIELDS];

_fld[_curidx] = new BField(row, col, "problem here-Virtual Element", framed);

I have to figure out how to override the virtual element of the BField constructor. I'll come back to this when I figure it out. Go Team!

Wednesday, March 17, 2010

Casting

I bloody hate casting. I have avoided it until this point.

I spent about half an hour knowing what I wanted to "return" from one of my functions, but getting a compilation error C2440, something along the lines of can't change type1 into type2. Took me a while to get why return *this was attempting to return an instance of BForm (the class I had declared and was working in) instead of BField, which was the type I was supposed to return. It was strange also because I had thought I had previously attempted casting for BField, but I suppose I must have forgotten the &. Still.... Damn you casting! I will conquer you and CRUSH you between my toes! Victory!!!

So just to recap:
BField& BForm::operator[](unsigned int index){
return (BField&)*this;
}
does nothing, but still, VICTORY!!! *kicks casting*