Static issue

Hi, when I make my program it shows this error:

error LNK2005: "public: static int CRocket::moja" (?moja@CRocket@@2HA) already defined in Rocket.obj

Anyone knows how to pass through this?
Only in declaration you specify it as static. Try removing static keyword in definition of the function.
Actually i have a public variable called 'moja' in class CRocket. Declaration looks like this:
static int moja;
And then in .h file after class declaration i have:
int CRocket::moja=0;
When i use this variable in .cpp file, for example in constructor:
moja++;
i have error from my first post.
Try putting the definition
int CRocket::moja=0;
in the .cpp file instead. Based on what you posted, I assume the header file is being included in multiple locations, and so the static variable 'moja' is being defined multiple times.

If that doesn't fix your problem(s), please post more code :)

--Rollie
I've just found solution. I put line:
int Rocket::moja=0;
into .cpp file.

We wrote our posts in the same minute. As you can see, you're right. Thank you :).
Last edited on
Topic archived. No new replies allowed.