Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your help!

We need 7 developers from Canada and 18 more from Australia to help us complete a research survey.

Support our site by taking a quick sponsored survey and win a chance at a $50 Amazon gift card. Click here to get started!


static variables name clash


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 noatom   Members   -  Reputation: 853

Like
0Likes
Like

Posted 31 March 2013 - 07:18 AM

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



Sponsor:

#2 Hodgman   Moderators   -  Reputation: 42188

Like
0Likes
Like

Posted 31 March 2013 - 07:24 AM

That should probably be static int i=10;



#3 Bacterius   Crossbones+   -  Reputation: 11732

Like
0Likes
Like

Posted 31 March 2013 - 07:26 AM

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.”


#4 noatom   Members   -  Reputation: 853

Like
0Likes
Like

Posted 31 March 2013 - 07:26 AM

yea...you are right...damn






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS