Search code examples
c++syntax

Why should we use "::" operator on global functions / objects?


I have seen this used in various places. C++ programmers will often use the :: operator right before a global function call.

e.g

::glGenBuffers( 1, &id );

Why is this? Why not just use:

glGenBuffers( 1, &id );

Solution

  • To avoid accidental namespace clashing. For example if you current namespace would have glGenBuffers which does something different from the "good" glGenBuffers with :: you can specify to call the glGenBuffers which is in the global namespace.