I'm having some trouble figuring this out.
I have a class heirarchy
Project
--> SimpleProject
--> MinorProject
--> MajorProject
Now a simple project and a minor project can be merged to create a simple project, a simple project and a major project can be merged to create a major project. Basically any project can be merged with any other project which creates a new project.
A simple project contains one and only one task. A Minor project contains a list of tasks, so merging a simple and minor project would create a new minor project with the list of the previous minor project and with the task from the simple project added to it. Also a major project is just like a minor project but with dependency's between tasks. So merging a major and a minor gives a major. Does this all make sense?
So basically i want to write a function which does this. I have been told it can be done using Dynamic Binding but im not seeing how...
Here are my class definition files if that helps you picture this more
Project.h:
Code:
#ifndef PROJECT_H
#define PROJECT_H
// forward declaration
class Task;
class Project
{
public:
Project();
Project(const Project &);
virtual ~Project();
// some pure virtual functions
virtual void AddTask(Task *) = 0;
virtual void DoTask() = 0;
virtual bool HasTasks() = 0;
private:
// still to add...
};
#endif
SimpleProject.h:
Code:
#ifndef SIMPLEPROJECT_H
#define SIMPLEPROJECT_H
#include "Project.h"
#include "Task.h"
class SimpleProject : public Project
{
public:
SimpleProject();
SimpleProject(const SimpleProject &);
~SimpleProject();
void AddTask(Task *);
void DoTask();
bool HasTasks();
SimpleProject & operator=(const SimpleProject & other);
friend std::ostream & operator<<(std::ostream & os,
const SimpleProject & sp);
friend bool operator==(const SimpleProject & left,
const SimpleProject & right);
friend bool operator!=(const SimpleProject & left,
const SimpleProject & right);
private:
Task *task;
// the total number of tasks
int numTasks;
};
#endif
MinorProject.h
Code:
#ifndef MINORPROJECT_H
#define MINORPROJECT_H
#include <list>
#include "Project.h"
#include "Task.h"
class MinorProject : public Project
{
public:
MinorProject();
MinorProject(const MinorProject &);
~MinorProject();
void AddTask(Task *);
void DoTask();
bool HasTasks();
MinorProject & operator=(const MinorProject &);
friend std::ostream & operator<<(std::ostream &, const MinorProject &);
friend bool operator==(const MinorProject &, const MinorProject &);
friend bool operator!=(const MinorProject &, const MinorProject &);
private:
list<Task> *task_list;
};
#endif
MajorProject.h (this one is not yet competed...):
Code:
#ifndef MAJORPROJECT_H
#define MAJORPROJECT_H
#include "Project.h"
#include "Task.h"
#include <list>
#include <vector>
class MajorProject : public Project
{
public:
MajorProject();
MajorProject(const MajorProject &);
//MajorProject(list<Task> *, vector<int *> *);
~MajorProject();
void AddTask(Task *);
void AddDependency(const vector<int> &);
void DoTask();
bool HasTasks();
MajorProject & operator=(const MajorProject & other);
friend std::ostream & operator<<(std::ostream & os, const MajorProject & mp);
friend bool operator==(const MajorProject & left, const MajorProject & right);
friend bool operator!=(const MajorProject & left, const MajorProject & right);
private:
list<Task> *task_list;
vector<vector<int>> *depend_vec;
};
#endif
If anyone can point me int he rigth direction i would appreciate that.