2

I have a enumerations named Color, Return_main_menue and Playertype in including.h like so:

enum Color { Red, Orange, Grey, Blue, Green, White, Purple };
enum Return_main_menue { Start, Credits, Help };
enum Playertype { Computer, Human };

I've also a source file named tools.cpp plus the tools.h tools.h:

#include "including.h"
Return_main_menue mainmenue();

tools.cpp:

Return_main_menue mainmenue()
{
// function which return Start, Credits or Help
}

I use the mainmenue() in my main.cpp:

Return_main_menue mainm = mainmenue();

But the compiler returns the error:

.../einbindung.h:7: error: multiple definition of 'enum Farbe'
.../einbindung.h:7: error: previous definition here
and so on for the other enums
Cœur
  • 37,241
  • 25
  • 195
  • 267
PEAR
  • 685
  • 3
  • 10
  • 20
  • 1
    See this question: http://stackoverflow.com/questions/14290026/linking-h-files-with-c-with-ifdef-header-guards – duncan May 20 '14 at 13:54

1 Answers1

11

Use include guards or #pragma once in headers to prevent multiple definitions in the same translation unit.

Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625