Jump to content
  • Advertisement
Sign in to follow this  
freeworld

how does using :: without something before it work.

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

I really don't know the words to describe this but i've been seeing it more and more, and I just read someone elses post with it.


if( !sInitialized )
{
__int64 l_TicksPerSec;
::QueryPerformanceFrequency((LARGE_INTEGER*)&l_TicksPerSec);
sf = 1.0 /(double)l_TicksPerSec;
sInitialized = true;
}



notice before the QueryPerformance thre is the ::, now I thought that signified scope or relation of the function. How is it working here?

Share this post


Link to post
Share on other sites
Advertisement
Exactly the same thing. "::QueryPerformanceCounter" specifies the identifier "QueryPerformanceCounter", in the scope "". That is, in the global namespace.

Think about it this way:


int foo()
{
return 3;
}

namespace bar
{
int foo()
{
// delegate to outer foo
return ::foo() + 1; // how else could you access the non-namespaced foo?
}
}

Share this post


Link to post
Share on other sites
Quote:
Original post by magorian
Behold, the scope resolution operator in all its glory.

But I don't see why it would be needed in the case you posted.


Because Windows API is a story in itself. Being invented before/alongside C++, there are many namespace conflicts, so for Windows-centric projects, in the interest of consistency, API calls are often always prefixed with ::

Share this post


Link to post
Share on other sites
Which solves about a third of them. I think every developer of a certain age remembers the first time he tried to name a member function CreateWindow, then use it from a file that included <windows.h>. [grin]

Share this post


Link to post
Share on other sites
I generally associate it with MFC. MFC wraps the Windows API and a lot of MFC functions are named the same as the Windows API function that they wrap. If for some reason you need to call the Windows API function rather than the MFC function, you need to use the scope resolution operator.

Share this post


Link to post
Share on other sites
Quote:
Original post by Sneftel
Which solves about a third of them. I think every developer of a certain age remembers the first time he tried to name a member function CreateWindow, then use it from a file that included <windows.h>. [grin]


I named some variable or function min, then compiler made me cry...

Share this post


Link to post
Share on other sites
Well, at least that can usually be solved by defining WIN32_LEAN_AND_MEAN or NO_MIN_MAX. Unless of course you happen to be using some other library which relies on min/max as macros and has entangled itself throughout the code.

I think I ran into that problem once but everything from that realization to waking up covered in other people's blood is just a huge hole in my memory.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!