For school I have to write an agenda, it has to hold data about exams, tasks and lectures
I'm having trouble accessing an enum in my struct.
My struct looks as follows:
struct Item{
enum {TASK, EXAM, LECTURE} entryType;
char* name;
char* course;
time_t start;
time_t end;
union
{
struct Task* task;
struct Exam* exam;
struct Lecture* lecture;
} typeData;
};
Now I have to set the type of the item using my enum. This struct is defined in Item.h. In Item.c which includes Item.h I use the following code:
struct Item* createItem(char* type){
struct Item* newItem;
newItem = (struct Item *) malloc (sizeof(struct Item));
if (strcmp(type, "Task") == 0)
{
//newItem->entryType = newItem->TASK;
newItem->typeData.task = createTask();
} else if (strcmp(type, "Exam") == 0)
{
//newItem->entryType = newItem->EXAM;
newItem->typeData.exam = createExam();
} else if (strcmp(type, "Lecture") == 0)
{
//newItem->entryType = newItem->LECTURE;
newItem->typeData.lecture = createLecture();
}
return newItem;
}
The commented code gives me the error (for TASK for example):
error C2039: 'TASK' : is not a member of 'Item'