Everything seems to compile fine, but I'm getting a run-time error. What I don't understand is these are identical, the only difference being one is accessing an object directly and the other is accessing a reference to the object. For some reason I can declare the reference no problem, but as soon as I try to access it, it breaks.
Code:
//part of cEntity.cpp
void cEntity::SetWornHead(cArmor * head)
{wornhead = head;}//wornhead declaration: cArmor * wornhead
cArmor* cEntity::GetWornHead(void)
{return wornhead;}
void cEntity::SetWornShoulders(cArmor shoulders)
{wornshoulders = shoulders;} //wornshoulder declaration: cArmor wornshoulders
cArmor cEntity::GetWornShoulders(void)
{return wornshoulders;}
//constructor
cEntity::cEntity(char* thisname)
{
SetWornHead(&gArmorTravelersHead);
SetWornShoulders(gArmorTravelersShoulders)
GetWornHead()->GetArmorClass(); //threw that in just to see if it would work in the constructor, and it did.
}
Everything up to here works, butwhen i want to do something like this, I get the error
Code:
void cEntity::SetAC(void)
{
ac = GetWornHead()->GetArmorClass() + //doesnt work
GetWornShoulders().GetArmorClass();//works
//GetArmorClass() is a member of the class cArmor
}