So suppose I have the following two files:
// main.h
struct Player {
int health;
int stamina;
};
// main.c
#include "main.h"
#include <stdio.h>
int main() {
struct Player newPlayer;
newPlayer.health = 100;
newPlayer.stamina = 100;
return 0;
}
This works fine.
Now suppose I have these two files:
// main.h
struct Player {
int health;
int stamina;
};
struct Player defaultPlayer;
defaultPlayer.health = 100; // error here
defaultPlayer.stamina = 100; // error here
// main.c
#include "main.h"
#include <stdio.h>
int main() {
struct Player newPlayer = defaultPlayer;
return 0;
}
The error in question is:
Unknown type name 'defaultPlayer'
[clang: unknown_typename]
My question is: Why can't I define a default struct
in the .h
file?