Originally Posted by
bithub
Dont include myfile.cpp in main.cpp. Instead place the following in myfile.cpp:
Code:
extern int myglobalinteger=0;
I believe you shouldn't try to initialize it or you will get linker errors.
Try setting it up like this:
Code:
//main.cpp
#include "myfile.h"
int myglobalinteger;
int main()
{
//blah
//do something with mydirectxobject
mydirectxobject->method1();
myfunction();
}
Code:
//myfile.h
extern object mydirectxobject;
void myfunction(int someparam);
Code:
//myfile.cpp
extern int myglobalinteger;
object mydirectxobject = NULL;
void myfunction(int someparam)
{
//do something with myglobalinteger
myglobalinteger+=1
}
It is generally bad practice to include .cpp files (the only exception I can think of is inline/template functions, and even then I think you should use a .inl file or include the definitions in the header)