hey folks,
maybe it could be a noob question, but just noticed that everytime i declare a variable outside the scope of a class i get the following error:
multiple definition of (variable name)
it is related with some fmod stuff…
is that normal?
i’m on ubuntu 10.04 and codeblocks,
thanks in advance!
you cannot declare variables in a .h cause then each cpp, that includes that .h will create a copy of the variable. you can declare it as an extern:
extern int myvar;
and then actually create the variable in a .cpp just by normally declaring it. but you should avoid that as it could be super problematic.
if it’s happening in a .cpp then you actually have two variables with the same name in different cpps look more carefully at the error messages there’s the 2 locations where the variables are defined.
to solve it in the case of cpp’s you can declare a variable to only exist in that file by using static:
static int myvar=0
once again, thanks Arturo!
=]