static variables name clash

Started by
2 comments, last by noatom 11 years ago

So I have an exercise in my book that says: prove that file static variables in header files don't clash with each other when included in more than one cpp file.

So I have a header file that contains just: int i=10;

and 2 cpp files that include that header file.

When i try to compile->fatal error LNK1169: one or more multiply defined symbols found

Advertisement

That should probably be static int i=10;

Also, it's probably not a good idea to call a global variable "i". Such a variable name is very common for loops or other things.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

yea...you are right...damn

This topic is closed to new replies.

Advertisement