I'd like to know if it is best practice to initialize members of an abstract class (has at least one pure virtual member-function, possibly the dtor). The other choice is to do it in the inheriting classes.
Initializing in inheriting class
class IPlayer
{
public:
virtual ~IPlayer() {};
protected:
bool m_alive;
};
class Bomber : protected IPlayer
{
public:
Bomb(bool t_alive = true)
{
m_alive = t_alive;
}
~Bomb();
};
Initializing in parent, abstract class
class IPlayer
{
public:
virtual ~IPlayer() {};
protected:
bool m_alive { true };
};
class Bomber : protected IPlayer
{
public:
Bomb();
~Bomb();
};
Which one should I prefer, and why?