Reputation: 677
Ok say I want to define a terrain enum as
enum terrain {MOUNTAIN, GRASS};
or something.
How would I make this enum something that is defined in all the classes in my project?
Upvotes: 5
Views: 9110
Reputation: 992857
Put your enum
declaration in a header file:
#ifndef TERRAIN_H
#define TERRAIN_H
enum terrain {MOUNTAIN, GRASS};
#endif
(The #ifndef
/#define
pair is an include guard, you can read about those elsewhere.)
#include <stdio.h>
#include "terrain.h"
// your code here
Include the terrain.h
file in every source file where you need it. You can also include a header from another header file if you need to.
Upvotes: 11