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?
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)
:: is simply the global namespace, ive seen it done a few times, just a coding style really.
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?
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...
Quote:Original post by jperaltaQuote: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!
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement