The :: (scope resolution) operator is used to get hidden names due to variable scopes so that you can still use them. The scope resolution operator can be used as both unary and binary.
In C++, scope resolution operator is ::. It is used for following purposes.
1) To access a global variable when there is a local variable with same name.
2) To define a function outside a class.
3) To access a class’s static variables.
4) In case of multiple Inheritance.
5) For namespace.
6) Refer to a class inside another class.
1) To access a global variable when there is a local variable with same name:
| // C++ program to show that we can access a global variable// using scope resolution operator :: when there is a local // variable with same name #include<iostream> usingnamespacestd;intx;  // Global xintmain(){intx = 10; // Local xcout << "Value of global x is "<< ::x;cout << "\nValue of local x is "<< x;  return0;} | 
Output:
Value of global x is 0 Value of local x is 10 2) To define a function outside a class.
| // C++ program to show that scope resolution operator :: is used// to define a function outside a class#include<iostream> usingnamespacestd;classA {public: // Only declarationvoidfun();};// Definition outside class using ::voidA::fun(){cout << "fun() called";}intmain(){A a;a.fun();return0;} | 
Output:
fun() called
3) To access a class’s static variables.
| // C++ program to show that :: can be used to access static// members when there is a local variable with same name#include<iostream>usingnamespacestd;classTest{staticintx;  public:staticinty;   // Local parameter 'a' hides class member// 'a', but we can access it using :: voidfunc(intx)  { // We can access class's static variable// even if there is a local variablecout << "Value of static x is "<< Test::x;cout << "\nValue of local x is "<< x;  }};// In C++, static members must be explicitly defined // like thisintTest::x = 1;intTest::y = 2;intmain(){Test obj;intx = 3 ;obj.func(x);cout << "\nTest::y = "<< Test::y;return0;} | 
Output:
Value of static x is 1 Value of local x is 3 Test::y = 2;
4) In case of multiple Inheritance:
If same variable name exists in two ancestor classes, we can use scope resolution operator to distinguish.
| // Use of scope resolution operator in multiple inheritance.#include<iostream>usingnamespacestd;classA{protected:intx;public:A() { x = 10; }};classB{protected:intx;public:B() { x = 20; }};classC: publicA, publicB{public:voidfun(){cout << "A's x is "<< A::x;cout << "\nB's x is "<< B::x;}};intmain(){C c;c.fun();return0;} | 
Output:
A's x is 10 B's x is 20
5) For namespace
If a class having the same name exists inside two namespace we can use the namespace name with the scope resolution operator to refer that class without any conflicts
| // Use of scope resolution operator for namespace.#include<iostream>intmain(){std::cout << "Hello"<< std::endl;} | 
Here, cout and endl belong to the std namespace.
6) Refer to a class inside another class:
If a class exists inside another class we can use the nesting class to refer the nested class using the scope resolution operator
| // Use of scope resolution class inside another class.#include<iostream>usingnamespacestd;classoutside{public:intx;classinside{public:intx;staticinty; intfoo();};};intoutside::inside::y = 5; intmain(){outside A;outside::inside B;} | 


