N
Narf the Mouse
I'm currently working on a roguelike as an excercise in learning c++.
Anyway, I've set up a script parser to check a text file to find out
how many races there are, then dynamically alocate an array 'RaceClass
* RaceList = new RaceClass[NumRaces];'
Now, upon array creation, each member of that array also gets a
dynamically created list of twenty parent class body parts:
' BodyClass * BodyPart;
RaceClass () {
BodyPart = new BodyClass[20];
};'
Then the text file for each race is parsed to see how many of different
types of limbs that race has, and limbs are alocated.
Now, this works:
' if ( fieldData[1] == "Arm" ) {
NewBodyPart = new ArmClass;
CurRace.BodyPart[t] = (const BodyClass&)
*NewBodyPart;
};'
I know this because the constructer for the 'ArmClass' alocated the
right variable.
This doesn't:
' if ( fieldData[1] == "Leg" ) {
NewBodyPart = new LegClass;
CurRace.BodyPart[t] = (BodyClass*) NewBodyPart;
};'
I know this because Dev cpp returns an error on it.
Specifically:
191 no match for 'operator=' in '*(CurRace->RaceClass::BodyPart +
(+(((unsigned int)t) * 12u))) = NewBodyPart'
191 candidates are: BodyClass& BodyClass:perator=(const BodyClass&)
The second is what I used to create the fix.
My guess is, it gets a pointer to NewBodyPart, then turns the pointer
into a reference for BodyClass - But I'm a newbie and would appreciate
an explanation of what I just did. Thanks.
Anyway, I've set up a script parser to check a text file to find out
how many races there are, then dynamically alocate an array 'RaceClass
* RaceList = new RaceClass[NumRaces];'
Now, upon array creation, each member of that array also gets a
dynamically created list of twenty parent class body parts:
' BodyClass * BodyPart;
RaceClass () {
BodyPart = new BodyClass[20];
};'
Then the text file for each race is parsed to see how many of different
types of limbs that race has, and limbs are alocated.
Now, this works:
' if ( fieldData[1] == "Arm" ) {
NewBodyPart = new ArmClass;
CurRace.BodyPart[t] = (const BodyClass&)
*NewBodyPart;
};'
I know this because the constructer for the 'ArmClass' alocated the
right variable.
This doesn't:
' if ( fieldData[1] == "Leg" ) {
NewBodyPart = new LegClass;
CurRace.BodyPart[t] = (BodyClass*) NewBodyPart;
};'
I know this because Dev cpp returns an error on it.
Specifically:
191 no match for 'operator=' in '*(CurRace->RaceClass::BodyPart +
(+(((unsigned int)t) * 12u))) = NewBodyPart'
191 candidates are: BodyClass& BodyClass:perator=(const BodyClass&)
The second is what I used to create the fix.
My guess is, it gets a pointer to NewBodyPart, then turns the pointer
into a reference for BodyClass - But I'm a newbie and would appreciate
an explanation of what I just did. Thanks.