我已经找到了这个:在C++中的外部枚举
但它并没有对我有太大帮助。我有一个config.h和config.cpp,在config.h中我有我的枚举:
#ifndef CONFIG_H
#define CONFIG_H
extern enum Items;
#endif
而在我的config.cpp文件中,我已经声明了该枚举:
#include "config.h"
enum Items {
PAC = 'C', GHOST = '@', FRUIT = 'o', POINTS = '.', WALL = '#', EMPTY = ' ', UNDEFINED = '+'
} fieldItems;
但是如果我尝试编译它,编译器会给我以下错误:
config.cpp:20:13: error: a storage class can only be specified for objects and functions
extern enum Items;
^