Page 53 - DCAP404 _Object Oriented Programming
P. 53
Object-oriented Programming
Notes cout << “n=” <<n<< “\n”;
cout << “m=” <<m<< “\n”;
cout << “::m=” <<::m<< “\n”;
}
cout << “\n we are in outer block \n”;
cout << “m=” <<m<< “\n”;
cout << “::m=” <<::m<< “\n”;
}
The output of the program:
We are in inner block.
n = 20
m = 30
::m = 10
We are in outer block
m = 20
::m = 10
Did u know? What is the use of scope resolution operator?
The :: (scope resolution) operator is used to qualify hidden names so that you can still use
them.
2.6 Member Dereferencing Operators
Once a class (or a structure) is defined, its members (both data and methods/function) can be
accessed (or referenced) using two operators - (.) dot operator and (->) arrow operator. While (.)
operator takes class or struct type variable as operand, (->) takes a pointer or reference variable
as its operand.
With class and structure type variables, (.) dot operator is used to reference the members, as
shown in the following program code:
struct abc
{ int a, b, c; };
class pqr
{ int p, q, r;
int doit(); };
abc structone;
pqr classone;
structone.a = 20;
structone.b = 120;
46 LOVELY PROFESSIONAL UNIVERSITY