0
votes

Title. I'm using pragma once in all relevant files but I'm still getting this error. I'd appreciate any help.

Event.h:

    //This file is relevant to the others.
    #pragma once
    enum QueueType {Interactive, Noninteractive};
    enum EventType {Start, Core, SSD, TTY};

    struct Event {

        //Event info
        int time;
        EventType e;
        int PID;
        QueueType q;
    };

Queue.h:

#pragma once
#include "Event.h"

//Problem code
struct nodeType {
    Event info;
    nodeType *link;
};
//Everything else in the file is basic Queue functions. Will provide if needed.

PriorityQueue.h:

#pragma once
#include "Event.h"


struct nodeType {
    Event info;
    nodeType *link;
};
//Also contains Priority Queue functions

main.cpp:

#include <iostream>
#include <string>
#include <assert.h>
#include "Event.h"
#include "Queue.h"
#include "PriorityQueue.h"
using namespace std;

//Also includes some test code 

In the implementation files for Queue.h and PriorityQueue.h I use pragma once and include their respective header files as well as iostream and assert. I include using namespace std cause I'm lazy. All the other research I've done seemed to come down to people not using include guards which I don't think is the problem here. Any help would be appreciated.

1

1 Answers

2
votes

You've defined the struct nodeType twice, in two different headers. This will cause your error. Only define it in one header, or if they're meant to be different types, either give them different names or put them in separate namespaces.

#pragma once or include guards only prevent multiple inclusions of the particular header; if you violate the One Definition Rule in the way you are currently doing so include guards won't save you.