+ 4
What's the use of scope Resolution operator in cpp
4 odpowiedzi
+ 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]
+ 9
Here is one
- Calling namespace values
https://code.sololearn.com/cCvrMnU5okQ1/?ref=app
+ 7
And another one
- Calling functions and classes from namespaces
https://code.sololearn.com/c2whMXv48O1K/?ref=app