C
Christopher
This is going to be hard to explain. But I am looking for rules on
deriving nested classes in a scenario like the following:
class TaskLauncher
{
// launches tasks which are child threads
typedef std::vector<BaseTask *> Tasks
Tasks m_tasks;
// desire to be able to dynamic cast BaseTask pointer to a concrete
task type
// and be able to retreive its stats when stats can be differant
types
};
class BaseTask
{
public:
...
private:
class TaskStats
{
public:
virtual const std::string GetStats() const;
...
private:
m_somestat;
}m_stats;
};
class Task1 : public BaseTask
{
public:
...
private:
class Task1Stats : public TaskStats
{
public:
virtual const std::string GetStats() const;
private:
m_somestat;
m_otherstat;
}m_stats;
};
I don't really nest classes very often, but I figured it would be
convienant when users of the class want a particualr kind of stats
that they can qualify it with the task type. i.e Task1::m_stats or
BaseTask::m_stats and get the proper type of stats.
Do the names of member variables get overidden properly? i.e does
Task1::m_stats contain a m_otherstats member?
Is there a problem with Task1 being derived from BaseTask while its
nested Task1Stats is derived from TaskStats?
Did I get the syntax correct in my scenario example?
deriving nested classes in a scenario like the following:
class TaskLauncher
{
// launches tasks which are child threads
typedef std::vector<BaseTask *> Tasks
Tasks m_tasks;
// desire to be able to dynamic cast BaseTask pointer to a concrete
task type
// and be able to retreive its stats when stats can be differant
types
};
class BaseTask
{
public:
...
private:
class TaskStats
{
public:
virtual const std::string GetStats() const;
...
private:
m_somestat;
}m_stats;
};
class Task1 : public BaseTask
{
public:
...
private:
class Task1Stats : public TaskStats
{
public:
virtual const std::string GetStats() const;
private:
m_somestat;
m_otherstat;
}m_stats;
};
I don't really nest classes very often, but I figured it would be
convienant when users of the class want a particualr kind of stats
that they can qualify it with the task type. i.e Task1::m_stats or
BaseTask::m_stats and get the proper type of stats.
Do the names of member variables get overidden properly? i.e does
Task1::m_stats contain a m_otherstats member?
Is there a problem with Task1 being derived from BaseTask while its
nested Task1Stats is derived from TaskStats?
Did I get the syntax correct in my scenario example?