• Advertisement
Sign in to follow this  

::MessageBox

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

if(!InitWindowsApp(hInstance, nShowCmd)) 
	{
		::MessageBox(0, "Init - Failed", "Error", MB_OK);
		return 0;
	}
what is the purpose of the "::" operators at the beginning of the messagebox function?

Share this post


Link to post
Share on other sites
Advertisement
The :: tells the compiler to use the MessageBox function at the global scope - i.e. not within any classes or namespaces. This is useful if you are, for example, using a class that contains a function called MessageBox but you want to call the Win32 function by the same name.

Share this post


Link to post
Share on other sites
"::" without left operand make it use global namespace's MessageBox function.
The left operand indicate the object(class), the right operand indicate member function/variable.

Example:

class example {
public:
static int Hello;
static MessageBox(){};
};

void main {
example::Hello = 15; // This will set "example" class's static variable "Hello" to 15
example::MessageBox(); // This will call "example" class's static function "MessageBox"
}

Share this post


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

  • Advertisement