1

In input.h I define eventFunctions like so:

multimap <Uint8, function<void(SDL_Event&)>> eventFunctions;

Input.h is surrounded by:

#ifndef INPUT_H
#define INPUT_H
//code
#endif

However, on compilation I get this: multiple definition of eventFunctions Referring to every file that includes input.h. I also added this to input.h to see how many times it gets processed during compilation: #warning "entered input_h" The warning prints several times (every time it is included), showing that it is being processed more than once despite the include guards.
What am I doing wrong?

Ran Eldan
  • 1,350
  • 11
  • 25
w4etwetewtwet
  • 1,330
  • 2
  • 10
  • 20

1 Answers1

4

The header file should contain declarations, not definitions. The definition should be in a single C++ file, not all of them. What you should do is have a single C++ file with this definition, and use an "extern" declaration in the header.

See this answer for more explanations: How do I use extern to share variables between source files?

Community
  • 1
  • 1
Rémi
  • 3,705
  • 1
  • 28
  • 39