Scope resolution operator in C++
The scope resolution operator can be used as both unary and binary. You
can use the unary scope operator if a namespace scope or global scope name is
hidden by a particular declaration of an equivalent name during a block or
class.The scope resolution operator to use class names or class member names.
Fig: Scope Resolution Operator In C++
Syntax:
return type class name ::
function name()
{
function of body;
}
Example:
void BCA :: display()
{
cout<<”pramod dwivedi display”;
}
We have a global variable of
name num and a local variable of name num, to access global num ,
now to use the scope resolution
operator.
Program:
#include<iostream.h>
#include<conio.h>
int num=30; //global variable
void main()
int num; //local variable
cout<<”input value”;
cin>>num;
cout<<”local variable =”<<num<</n;
cout<<”global variable=”<< ::num<</n;
getch();
}
Output:
Input value 30
Local variable 30
Global variable 30
No comments:
Post a Comment