I have a class called Warrior that has uint m_health and uint m_maxHealth attributes.
I want my constructor to take parameters Warrior(uint health, uint maxHealth).
Now I've studied C++ a lot and I know all the syntax etc, but it's hard to find tutorials on how to use the stuff etc. so I don't really know how should I define health and maxHealth when health obviously can't be higher than maxHealth :/
Here are few methods I thought of:
// method 1
Warrior::Warrior(uint health, uint maxHealth) :
m_health((health > maxHealth) ? maxHealth : health),
m_maxHealth(maxHealth)
{}
// method 2
Warrior::Warrior(uint health, uint maxHealth) :
m_maxHealth(maxHealth)
{
if (health > maxHealth) {
m_health = maxHealth;
}
else {
m_health = health;
}
}
I'm sure there are other ways too. Sorry if this is just an opinion question, but if there's a "preferred" way in C++, what would it be?