Wat is influence resolution?
Answer:
in C/C++ we enjoy an operator '::'.. This hand is know as scope resolution hand..
This operator is used to access a worldwide variable which is in some way accessible due to existance of a variable surrounded by block scope( or function scope) with indistinguishable name..
Example...
int bill;
blankness somefunc()
{
int bill; // now you can't access the intercontinental 'bill' directly..
// do something...
cout<<bill; // this will output the value of irregular 'bill' which is declared inside the function
cout<< ::bill;// now you'll grasp the value of the 'bill' which is worldwide declared
// dosomething
}
The :: (scope resolution) operator is used to qualify masked names so that you can still use them. You can use the unary range operator if a namespace influence or global compass name is invisible by an explicit declaration of like peas in a pod name surrounded by a block or class. For example:
int count = 0;
int main(void) {
int count = 0;
::count = 1; // set global count to 1
count = 2; // set local count to 2
return 0;
}
The avowal of count declared in the main() function hide the integer named count declared surrounded by global namespace breadth. The statement ::count = 1 accesses the unstable named count declared contained by global namespace latitude.
You can also use the class scope worker to qualify class names or class contestant names. If a class bough name is concealed, you can use it by qualifying it next to its class name and the class circle operator.
In the following example, the affirmation of the variable X hide the class type X, but you can still use the static class member count by qualify it with the class type X and the influence resolution operator.
#include <iostream>
using namespace std;
class X
{
public:
static int count;
};
int X::count = 10; // outline static data beneficiary
int main ()
{
int X = 0; // hide class type X
cout << X::count << endl; // use static member of class X
}
Related Questions: