Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multiple definition of enumeration [duplicate]

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
like image 280
PEAR Avatar asked Dec 14 '25 00:12

PEAR


1 Answers

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

like image 168
Luchian Grigore Avatar answered Dec 15 '25 14:12

Luchian Grigore