How do I make my main.cpp realize that I have declared all my stat structs in another file? I have added that file in my project, but it still gives those "not initialized" errors. Help?
//structs.cpp
#include <iostream>
usingnamespace std;
struct character
{
int HP;
int ammo;
};
character player {500, 20};
//main.cpp
#include <iostream>
int main ()
{
std::cout << player.HP;
return 0;
}
I added structs.cpp to my project. But when I run it, it gives an error that player.HP is not initialized.
The problem is that main.cpp doesn't know how your structure is defined or how and what a player is defined.
I suggest you put your structure definition in a header file, and make your "player" a variable local to some function and pass that variable to and from your functions as required.