16.6 SCOPE RESOLUTION OPERATOR AS UNARY OPERATOR

Earlier, we have seen the use of scope resolution operator in context of classes. This operator can be used as unary operator. Consider a case of a block. When we define a variable with the same name as that of a global variable, it shadows the global variable. Any reference in the block to this name results in local variable. For any reason we need global variable, we can precede the variable name with the scope resolution operator. See Program 16.10.

Problem: A college conducts tests with maximum marks 100. A global variable MAX is defined with value 100. A particular teacher conducts test with maximum marks 50. He also wants variable name MAX to store value 50 inside a block. Write a program ...

Get Object Oriented Programming with C++, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.