years ago before anyone heard about namespaces programmers had a terrible time avoiding name conflicts in their own code and the libraries they used. That was the main reason (I think) for the introduction of namespaces -- you can have as many objects with the same name as you wish as long as each object is contained in a different namespace. you will commonly see code such as
std::cout << "Hello Worod" << std::endl;
This is identifying the namespace (std) of cout and endl. For objects in global namespace, such as all the win32 api functions just preceed the object with two colons as in the following code. This is really more useful when there is another function called MessageBox() in another namespace that your program also might use. Its just telling the compiler which function to call.
::MessageBox(0,"Hello World","Message",MB_OK);
c++ classes have the same affect as formal namespace
class MyClass
{
MyClass();
static void SayHello() {std::cout << "Hello World" << std::endl;}
};
// call the SayHello method
MyClass::SayHello();
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Offline 21,953 posts
since Aug 2005