I have declared a string array in a header and want to use it in other headers and functions. I used extern and it works for one the headers but for the other one, it is empty. Program runs and there are no error messages.
Any help would be appreciated.
1 2
// I defined it in this header. For the example lets call this weapon.h
std::string weaponChoice[] {"bat", "pistol", "golf club", "rifle", "axe", "shovel", "knife", "tampons"};
I then put this in another header, lets say attack.h
extern std::string weaponChoice[];
I can use the array in this attack.h like this
std::cout << "# You hit him with " << weaponChoice[wC] << " and do " << weapon_damage << " damage!" << std::endl;
But I cannot use it in story.h
1 2 3
extern std::string weaponChoice[]; //This is what is in story.h
1 2
//It doesn't work in story.h. Just prints out a blank.
std::cout << "\t >> Enter '1' to attack zombie with " << weaponChoice[wC] << std::endl;