Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


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: 821

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: 40013

Like
0Likes
Like

Posted 31 March 2013 - 07:24 AM

That should probably be static int i=10;



#3 Bacterius   Crossbones+   -  Reputation: 11344

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: 821

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