'lo there folks,

MinGW's giving me 1 error I can't get rid of:

eventhandler.h|9|error: `element' has not been declared|
eventhandler.h|9|error: ISO C++ forbids declaration of `elem' with no type|

All code mentioned and I think needed:

eventhandler.h

#ifndef EVENTHANDLERH
#define EVENTHANDLERH

#include "element.h"

enum events {onClick, onHover};

typedef struct eventHandlerT {
    void(*func)(element *elem);
    events eventType;
} eventHandler;


#endif // EVENTHANDLERH

element.h

#ifndef ELEMETH
#define ELEMETH

#include "eventhandler.h"

class element {
    public:
    element();
    ~element();

    void processEvent(events event);

    vector<eventHandler> handlers;
    unsigned int ID;
    static unsigned int IDcount;
};


#endif // ELEMETH

Why is element not declared? I don't get that, the header is included right above it?

Any help is greatly appreciated,

>>Why is element not declared?
Because you have recursive includes -- each header file includes the other.

In eventhandler.h try this:

#ifndef EVENTHANDLERH
#define EVENTHANDLERH

class element;  // forward declaration of class

enum events {onClick, onHover};

typedef struct eventHandlerT {
    void(*func)(element *elem);
    events eventType;
} eventHandler;


#endif // EVENTHANDLERH

Thanks, it works, but...

That's where the guards (the #ifdef stuff) are for right? Not trying to be impolite, but why can't I include those headers with the guards in place?

>>That's where the guards (the #ifdef stuff) are for right?

Nope. The guards prevent the same include file from being processed more than once. For example:

#include "element.h"
#include "element.h" // this one will be ignored

Your program had a different problem. The preprocessor attempted to process the line that used element *elm but class element had not been fully defined yet. With forward references the class doesn't have to be fully defined in order to declare a pointer to it.

Ah, okay. Thanks for the explanation.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.