学校では、議題を書かなければならず、試験、タスク、講義に関するデータを保持する必要があります
構造体の列挙型にアクセスできません。
私の構造体は次のようになります。
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;
};
次に、列挙型を使用してアイテムのタイプを設定する必要があります。この構造体は Item.h で定義されています。Item.h を含む Item.c では、次のコードを使用します。
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;
}
コメント付きのコードでエラーが発生します(たとえば、TASKの場合):
エラー C2039: 'TASK' : 'Item' のメンバーではありません