+ 1
It's used to access a value which is in another scope. This can be used for various reasons. If you use a variable the program first searches it in the scope you are and then in other scopes. Let's say you have a global variable named x, but there is another variable named x in a function. When writing cout << x it outputs the value of the local x. When writing cout << ::x you output the value of the global x. Another example: You created a class and just declared the methods. To implement the code of the methods you use the scope resolution operator: class Foo{ void bar(); //just the declaration }; //implementation outside of the class void Foo::bar(){ cout << "blablabla"; }
13th Apr 2018, 8:43 AM
Alex
Alex - avatar