I am creating a class Item in c++:
class Status {
public:
int health;
Status() : health(10){}
Status(Status first, Status second)
{
//This overloads the constructor by being able to add two "Status"s
this->health = first.health + second.health;
}
class Character{
Status status;
Character() : status(20){}
}
class Item
{
Statuss status;
public:
Item() : status() {}
void UseItem(Character character, Item item)
{
//the passed characters status will equal the new status.
character.status = Status(character.status, item.status);
}
};
Item.UseItem(myCharacter, myItem);
When I include the character.h to the Item class I get a header loop, but if I don't include the header I have a undefined identifyer. How does forward declaration work for this?
Also, when I use the line:
character.status = Status(character.status, item.status);
and I actually referencing the character.status or am I creating a new instance of the class?
Sorry for asking such basic questions, It's hard understanding what you don't fully know.
Thanks in advance!
↧