Scope resolution operator

The scope resolution operator (: : ) in C++ is used to define the declared member functions (in the header file with cpp extension) of the in the cpp file one can define the normal functions or the number functions of the class. To differentiate from the normal functions with the member functions of the class, one needs to the use the scope resolution operator (: : ) in between the class name and the member function name, ship : : foo () where the ship is class and the foo () is member function in the ship. The other applications of the resolution operator is to resolve the scope of the variables if the identical variable name is used for local, global, and the data member of the class. If the resolution operator is placed between the class name and the data member belonging to the class than data name belonging to the particular class is affected. If the resolution operator is placed in front of the variable name than the global variable is affected. If no resolution operator is placed then the global the local variable is affected. You can inform the compiler to utilize the global identifier rather than local identifier through prefixing the identifier with : : the scope resolution operator.

: : identifier

Class name : : identifier

Name space : : identifier // the identifier can be a variable or a function.

If we have nested local scopes, the scope resolution operator does not provide access to identifier in the next outer most scope. It gives access to only the universal identifiers. This instance has two variables namely amount. The first one is global and consists of the value 123. The second is restricted to the main function. The scope resolution operator states the compiler to utilize the global amount in spite of the local one.

# include < iostream. h >

Using name space std;

Int amount = 123; // a global variable

Int main ()

{

Int amount = 456; // a local variable

Cout << : : amount << end l; // print the global variable

   Cout << : : amount << end l; // print the local variable

                 }

   Related Questions in Programming Languages

  • Q : Explain Command-line argument

    Command-line argument: The arguments passed to a program whenever it is run. The Java program receives such in the single formal argument to its major method: public static void main(String[] args)

  • Q : What is an Assembly language Assembly

    Assembly language: This is a symbolic language closely analogous to the instruction set of a Central Processing Unit. The program employed to translate a program written in assembly language is termed an assembler.

  • Q : Why is either inspection or walkthrough

    You were specified a chance to implement either inspections or walkthroughs. Based upon your personal experience that one would you decide? Please share your reason?

  • Q : Role of ScriptManagerProxy control?

    Explain the role of ScriptManagerProxy control?

  • Q : Define Factoring Problem Factoring

    Factoring Problem: Factoring is the action of dividing an integer into a set of smaller integers (or factors) which, when multiplied altogether, form the unique integer. For illustration, the factors of 15 are 3 and 5; the factoring trouble is to find

  • Q : What is Factory pattern Factory pattern

    Factory pattern: A pattern of class definition which is employed as a generator of instances of other classes. Frequently employed to form platform- or locale-particular implementations of abstract classes or interfaces. This decreases coupling betwee

  • Q : What is Block Block : The statements

    Block: The statements and declarations are enclosed between a matching pair of curly brackets ({ and }). For example, a class body is a block, as it is a method body. The block surrounds a nested scope level.

  • Q : How can Corba application has call back

    Describe how can Corba application has call back?

  • Q : Define the term Method signature Define

    Define the term Method signature: This is the synonym for method header.

  • Q : Web based programming homework

    Component 2 Task b: Task Description Computing students at this University who study on undergraduate courses require a method to view their module marks and to see how they are progressing on the module. You have been asked to develop a web

©TutorsGlobe All rights reserved 2022-2023.