Jump to content
  • Advertisement
Sign in to follow this  
mrmrcoleman

Just a quick question about scope in C++.

This topic is 4658 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

With same name variables, which takes precedence in the local scope, global or local? Seems like it must be local, but I am not 100%. Thanks, Mark

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
local

Share this post


Link to post
Share on other sites
its a bad idea to have two variables with the same name, it makes your program a little less clear...

Share this post


Link to post
Share on other sites
Local takes precedence; this is known as identifier shadowing. If your compiler does not complain loudly about you doing this, you need to up your warnings levels [wink]


rip-off is exactly right. If you need similar identifiers, strongly consider using a namespace or some other grouping mechanism to avoid shadowing. The compiler can figure it out just fine, but I guarantee that at some point, it'll confuse you...

Share this post


Link to post
Share on other sites
Thanks for all the feedback, and the warnings! It's not actually for use in a program, I am working my way through every C++ exam/test/quiz/multiple choice I can find in preparation for interviews which I will *hopefully* be having when I get my demos finished.

Mark

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!