+ 4

What's the use of scope Resolution operator in cpp

17th Oct 2017, 1:26 AM
IMRAN SHAIKH
IMRAN SHAIKH - avatar
4 ответов
+ 15
• Scope resolution operator: There are some uses for scope resolution operator "::". One of which related to access to a global variable when there is a local variable with the same name. #include <iostream> int n = 1000; int main() { int n = 2; std::cout << n << endl; // output: 2 if (n > 0) { int n = 5; std::cout << n << endl; // output: 5 if (n == 5) std::cout << ::n << endl; // output: 1000 } std::cout << n; // output: 2 } [https://code.sololearn.com/c7vyMeL1egYL]
17th Oct 2017, 6:04 AM
Babak
Babak - avatar
+ 9
Here is one - Calling namespace values https://code.sololearn.com/cCvrMnU5okQ1/?ref=app
17th Oct 2017, 2:23 AM
Manual
Manual - avatar
+ 7
And another one - Calling functions and classes from namespaces https://code.sololearn.com/c2whMXv48O1K/?ref=app
17th Oct 2017, 2:26 AM
Manual
Manual - avatar