steva
asked on
Scope operator
What is the meaning of the scope operator before LoadBitmap in the code below...
m_button.SetBitmap(::LoadB itmap(AfxG etInstance Handle(), MAKEINTRESOURCE(IDB_GREEN) ));
m_button is a CButton object assigned to an MFC dialog button. The goal here is to put the IDB_GREEN bitmap onto the button, and this code does do that, but the :: is not clear. I understand that normally you would use :: if you wanted to specify the class, on the left side, that the method, on the right side, is to come from, but the left side of this :: is not a class, it's a method of the CButton class. Curiously, the code works fine without the :: and I only put it in because the sample code I got this from had it.
Thanks for any thoughts,
Steve
m_button.SetBitmap(::LoadB
m_button is a CButton object assigned to an MFC dialog button. The goal here is to put the IDB_GREEN bitmap onto the button, and this code does do that, but the :: is not clear. I understand that normally you would use :: if you wanted to specify the class, on the left side, that the method, on the right side, is to come from, but the left side of this :: is not a class, it's a method of the CButton class. Curiously, the code works fine without the :: and I only put it in because the sample code I got this from had it.
Thanks for any thoughts,
Steve
ASKER
Ok, but how does ::LoadBitmap instruct the compiler to use the Win32 version? From everything I've read, :: separates a class on the left from a method on the right. What is the meaning, in general, when there's no class on the left?
in general :: instructs compiler get method from GLOBAL namespace.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
::LoadBitmap(AfxGetInstanc
instucts the compiler to explicitly choose the Win32 API 'LoadBitmap()' instead of 'CBitmap::LoadBitmap()', that's why the scope operator is being used - to avoid a potential naming conflict with that method.