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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With