Im having a very weird problem. Im defining some classes:
Project (base Class)
--> SimpleProject
--> MinorProject
--> MajorProject
Task
Now my project class definition is:
Code:
#ifndef PROJECT_H
#define PROJECT_H
#include "Task.h"
class Project
{
public:
Project();
Project(const Project &);
virtual ~Project();
virtual void AddTask(const Task & t) = 0;
virtual void DoTask() = 0;
virtual void HasTasks() = 0;
private:
// still to add...
};
#endif
As you can see, i have a pure virtual function AddTask which takes a constant reference to a task object as it's papameter. That means i had to include the Task.h file in Project.h.
Ok no problem, and my Task.h file is:
Code:
#ifndef TASK_H
#define TASK_H
#include "Project.h"
class Task
{
public:
Task();
Task(const Task & t);
Task(int, const Project &);
~Task();
void DoIt();
private:
int id;
Project *pp;
};
#endif
I have included Project.h because i want to have a pointer to the project which this task is associated with. So i have included Project.h in Task.h. Now if i do this everything goes crazy when i compile.
i get these error messages:
Code:
Error 1 error C2062: type 'int' unexpected d:\school\comp446\project\a3\task.h 12
Error 2 error C2238: unexpected token(s) preceding ';' d:\school\comp446\project\a3\task.h 12
Error 3 error C2143: syntax error : missing ';' before '*' d:\school\comp446\project\a3\task.h 19
Error 4 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int d:\school\comp446\project\a3\task.h 19
Error 5 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int d:\school\comp446\project\a3\task.h 19
Error 6 error C2062: type 'int' unexpected d:\school\comp446\project\a3\task.h 12
Error 7 error C2238: unexpected token(s) preceding ';' d:\school\comp446\project\a3\task.h 12
Error 8 error C2143: syntax error : missing ';' before '*' d:\school\comp446\project\a3\task.h 19
Error 9 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int d:\school\comp446\project\a3\task.h 19
Error 10 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int d:\school\comp446\project\a3\task.h 19
Error 11 error C2062: type 'int' unexpected d:\school\comp446\project\a3\task.h 12
Error 12 error C2238: unexpected token(s) preceding ';' d:\school\comp446\project\a3\task.h 12
Error 13 error C2143: syntax error : missing ';' before '*' d:\school\comp446\project\a3\task.h 19
Error 14 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int d:\school\comp446\project\a3\task.h 19
Error 15 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int d:\school\comp446\project\a3\task.h 19
Error 16 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int d:\school\comp446\project\a3\project.h 15
Error 17 error C2143: syntax error : missing ',' before '&' d:\school\comp446\project\a3\project.h 15
Error 18 error C2062: type 'int' unexpected d:\school\comp446\project\a3\task.h 12
Error 19 error C2238: unexpected token(s) preceding ';' d:\school\comp446\project\a3\task.h 12
Error 20 error C2143: syntax error : missing ';' before '*' d:\school\comp446\project\a3\task.h 19
Error 21 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int d:\school\comp446\project\a3\task.h 19
Error 22 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int d:\school\comp446\project\a3\task.h 19
Error 23 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int d:\school\comp446\project\a3\project.h 15
Error 24 error C2143: syntax error : missing ',' before '&' d:\school\comp446\project\a3\project.h 15
Is this caused by circular includes? Should i not be including Project/h in Task.h and Task.h in Project.h? Because ass soon as i do not use Task.h in Project/h the errors go away.
If the circular includes is the problem how would i use Task objects in my Project file and vice versa?