枚举的多重定义
Posted
技术标签:
【中文标题】枚举的多重定义【英文标题】:multiple definition of enumeration [duplicate] 【发布时间】:2014-05-20 13:51:02 【问题描述】:我在 include.h 中有一个名为 Color、Return_main_menue 和 Playertype 的枚举,如下所示:
enum Color Red, Orange, Grey, Blue, Green, White, Purple ;
enum Return_main_menue Start, Credits, Help ;
enum Playertype Computer, Human ;
我还有一个名为 tools.cpp 的源文件以及 tools.h 工具.h:
#include "including.h"
Return_main_menue mainmenue();
工具.cpp:
Return_main_menue mainmenue()
// function which return Start, Credits or Help
我在 main.cpp 中使用 mainmenue():
Return_main_menue mainm = mainmenue();
但是编译器返回错误:
.../einbindung.h:7: error: multiple definition of 'enum Farbe'
.../einbindung.h:7: error: previous definition here
and so on for the other enums
【问题讨论】:
看到这个问题:***.com/questions/14290026/… 【参考方案1】:在标题中使用include guards 或#pragma once
以防止在同一个翻译单元中出现多个定义。
【讨论】:
以上是关于枚举的多重定义的主要内容,如果未能解决你的问题,请参考以下文章