Originally posted by: TheLonelyPhoenix
You declare globals outside of the main function. You're getting multiple definition errors because you're including that header file in more than one code file, which has the same effect as copying-and-pasting your code into multiple places and thus attempting to define the same global twice or more.
And wrong forum.
Originally posted by: Vertimus
Originally posted by: TheLonelyPhoenix
You declare globals outside of the main function. You're getting multiple definition errors because you're including that header file in more than one code file, which has the same effect as copying-and-pasting your code into multiple places and thus attempting to define the same global twice or more.
And wrong forum.
If I declare the global outside of the main function, wouldn't i have the same problem?
Originally posted by: TheLonelyPhoenix
Originally posted by: Vertimus
Originally posted by: TheLonelyPhoenix
You declare globals outside of the main function. You're getting multiple definition errors because you're including that header file in more than one code file, which has the same effect as copying-and-pasting your code into multiple places and thus attempting to define the same global twice or more.
And wrong forum.
If I declare the global outside of the main function, wouldn't i have the same problem?
No, because your error stems from the fact that you put it in a header file which you are using in more than one place. Just declare it right before the main function in your main.cpp for a quick workaround.
Originally posted by: Vertimus
Originally posted by: TheLonelyPhoenix
Originally posted by: Vertimus
Originally posted by: TheLonelyPhoenix
You declare globals outside of the main function. You're getting multiple definition errors because you're including that header file in more than one code file, which has the same effect as copying-and-pasting your code into multiple places and thus attempting to define the same global twice or more.
And wrong forum.
If I declare the global outside of the main function, wouldn't i have the same problem?
No, because your error stems from the fact that you put it in a header file which you are using in more than one place. Just declare it right before the main function in your main.cpp for a quick workaround.
How would i use the variable in the other files then?
Originally posted by: TheLonelyPhoenix
Originally posted by: Vertimus
Originally posted by: TheLonelyPhoenix
Originally posted by: Vertimus
Originally posted by: TheLonelyPhoenix
You declare globals outside of the main function. You're getting multiple definition errors because you're including that header file in more than one code file, which has the same effect as copying-and-pasting your code into multiple places and thus attempting to define the same global twice or more.
And wrong forum.
If I declare the global outside of the main function, wouldn't i have the same problem?
No, because your error stems from the fact that you put it in a header file which you are using in more than one place. Just declare it right before the main function in your main.cpp for a quick workaround.
How would i use the variable in the other files then?
This sounds like very, very poor code design. But then again, you're already using globals, so I guess you're not particularly worried about it.
Declare the global variable BEFORE the #include directive of the file(s) that use it. Then you're set.