Original Post
I have a class TaskManager to which tasks (which derive from the base class Task) are added. When added, the task manager calls the task's Initialize() function. This function is pure virtual in the task base class and has to be implemented by deriving classes (-> InputTask). So far, I create a task and then add in to the task manager afterwards, like this: however, i'd like to do this in the task's constructor already, like this: this compiles fine, but when I run the app, it reports a pure virtual function call. here's how I call Initialize(): how can I make sure that the function of the derived class is being called instead of the base class's fucntion? As I said, it's declared pure virtual. Thank you!
m_pkInputTask = shared_ptr<InputTask>( new InputTask() );
Engine::GetTaskManager()->AddTask( shared_ptr<Task>(m_pkInputTask) );
Task::Task( long priority )
{
m_iPriority = priority;
Engine::GetTaskManager()->AddTask( shared_ptr<Task>(this) );
}
bool TaskManager::AddTask( const shared_ptr<Task> &task )
{
if( !task->Initialize() )
return false;
// ...
}