First, the code snippets I'm having issues with;
settings.h
namespace
{
int WINDOW_WIDTH;
int WINDOW_HEIGHT;
bool FULLSCREEN;
}
void settings_init();
settings.cpp
#include "DX_Constants.h"
void settings_init()
{
WINDOW_WIDTH = 1920;
WINDOW_HEIGHT = 1080;
FULLSCREEN = true;
}
main.cpp //just the important part..i haven't forgotton the other pieces needed by winapi
#include "settings.h"
int WINAPI WinMain(...)
{
settings_init();
if(//verifies values entered are seen here correctly ...NOTE triggers on != )
return false;
....code continues
}
my problems:
running the code in this format triggers the if statement check and closes the program.
if i remove the namespace anonymous i get LNK 2005 errors for the variables.
I CAN get the code to run if i simply comment out ALL of settings.cpp and put the function definition into the header file, but this is a shortfix to me.
what I need: obviously more understanding about header and secondary .cpp files...and probably linking. I have a couple books; "programming 2d games" by kelly, "beginning game programming" by harbour, and "visual C++ 2010" by horton. can someone point me in the direction of a place to learn in more detail my problem, which is getting the functions to live in .cpp while the declarations live in the header, or recommend a book that will teach me to understand these issues?
Solution edit: Credit goes to Mats Petersson (see the comments)
solution for the code ended up being;
- remove the anonymous namespace and brackets.
- apply extern prefix in front of the global variable type declarations in settings.h .
- ADD normal global variable declaration ( ex. int window_width; ) to the settings.cpp file.