Is it possible to specify which constructor to use when inheriting from a template based class? It seems like a basic thing, but I can't seem to figure out how to accomplish this in C++...
In the following code, I want to use a non-default constructor for the PlayerStats object when I create a PlayerActor (which inherits from the BaseActor template class).
class BaseStats {
public:
BaseStats ()
{
}
private:
};
class MonsterStats : public BaseStats {
public:
MonsterStats()
{
}
private:
};
class PlayerStats : public BaseStats {
public:
PlayerStats(
const bool is_new) :
m_is_new(is_new)
{
}
private:
const bool m_is_new;
PlayerStats(); //Don't want this being used...
};
template <class ActorStatsClass>
class BaseActor
{
public:
BaseActor()
{
}
private:
ActorStatsClass m_stats;
};
class MonsterActor: public BaseActor<MonsterStats> {
public:
MonsterActor()
{
}
private:
};
// This is where I'm not sure how to tell the template to use a non-default constructor...
// I get an error saying "PlayerStats::PlayerStats": cannot access private member declared in "PlayerStats". (Which is intended, but I don't want it to try and use the default constructor...)
class PlayerActor : public BaseActor<PlayerStats> {
public:
PlayerActor(const bool is_new)
{
}
private:
PlayerActor(); // Don't use this...
};