Jump to content
  • Advertisement
Sign in to follow this  

This topic is 4800 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

This thread actually has a content specific topic, believe it or not. Anyway, I'm skimming over a section of code my boss wrote to model part of my program after, and I see he's doing things like this: ::glMatrixMode(GL_MODELVIEW); ::glLoadIdentity(); I've never seen syntax such as this before. What's up with the preceding scope resolution operator there? Are these function calls of abitrary scope or something? They don't belong to any class that I'm aware of, they're just simple calls to functions in the gl library. I could ask my boss, but I figure if that's something every novice programmer knows and I've somehow missed it these last 7 years, I'd rather lose face in front of you guys (my tender, loving, gamedevers) than my boss. So what does it mean and should I already know this?

Share this post


Link to post
Share on other sites
Advertisement
They are functions with global scope... there's no reason to have the scope resolution operator there except to indicate the fact that they do have global scope (and possibly to clear up any resolution conflicts with names in included namespaces)

Share this post


Link to post
Share on other sites
Ohhh. So if he were to declare member functions in his class of the same name, he'd be safe when making these calls? In other words, if his class were named myClass, and a myClass::glLoadIdentity() existed, calling ::glLoadIdentity() would call the one out of the gl library, rather than the one he's defined?

Share this post


Link to post
Share on other sites
Quote:
Original post by CyberSlag5k
Ohhh. So if he were to declare member functions in his class of the same name, he'd be safe when making these calls?


Yes, but why he would declare functions with the exact same name as the OGL function...

Share this post


Link to post
Share on other sites
Quote:
Original post by jperalta
Quote:
Original post by CyberSlag5k
Ohhh. So if he were to declare member functions in his class of the same name, he'd be safe when making these calls?


Yes, but why he would declare functions with the exact same name as the OGL function...


Heh, well of course he wouldn't. It was just a pertinent example.

Quote:

cos its his boss, and they do sick and twisted things....


A very valid point [grin]

Thanks for the responses, everyone!

Share this post


Link to post
Share on other sites
Quote:
Original post by paulecoyote
just means global scope [smile] aka the unnamed namespace.


The global namespace and unnamed namespaces are quite different beasts.

CyberSlag5k - this should make things clear:


int foo() { return 42; }

namespace bar
{
int foo() { return 66; }

int bar() { return foo() + ::foo(); }
}


It's a bit like absolute and relative path for file names.

Share this post


Link to post
Share on other sites
Actually, that is done for the most part on laziness. Try it some time, with Visual C++'s intellisense, you can just do ::, then have the global names space, to which you can start typing the functions name, then hit enter to auto-complete it [smile] I do that all the time, but usually take out the :: when I am done.

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!