So I get that when you create a diamond in inheritance the most derived class needs to explicitly call the constructor of the virtual class's sub-objects in its initializer list.
But what about classes that inherit from a virtual class without that inheritance creating a diamond itself? e.g. Bow inherits from virtual base class Weapon, does Bow need a call to Object's constructor in its initializer list too and why?
I've become a bit tangled with all the classes inheritances and initializer lists and I just need to clear things up first before continuing and remove any unnecessary calls in my initializer lists.
Object's constructor takes a sf::Vector2f which is two floats. So far I've had Movable, Weapon and Projectile as virtual base classes since they are part of the diamond.
// sf::Vector2f is an SFML data type which consists of two floats
class Object
{
private:
sf::Vector2f m_pos;
public:
Object(sf::Vector2f start_pos) {m_pos = start_pos;};
}
class Movable : virtual public Object
{
public:
Movable(sf::Vector2f start_pos) : Object(start_pos) { ... };
}
class Weapon : virtual public Object
{
public:
Weapon(float shotDelay, bool isStealth) : Object(sf::Vector2f(0,0)) { ... };
}
class Projectile : public Movable
{
public:
Projectile (sf::Vector2f startPos, int damage) : Movable(startPos) { ... };
}
class Bow : public Weapon
{
public:
Bow() : Weapon(BOW_SHOT_DELAY, BOW_STEALTH) { ... };
}
class Grenade : public Weapon, public Projectile
{
public:
Grenade() : Weapon(GRENADE_SHOT_DELAY, GRENADE_STEALTH) {};//for Weapon
Grenade(sf::Vector2f startPos) : Projectile(startPos, GRENADE_DAMAGE);//for Projectile
}