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 why java is so important for

    The internet aided java to the forefront of programming. And java consequently has had a deep effect on the internet. The reason for this is highly simple: java uses the universe of objects that can travel freely in cyber space. In a network, two broad categories of

  • Q : Define the term Subordinate inner class

    Define the term Subordinate inner class: It is an inner class which executes well-defined subordinate tasks on behalf of its enclosing class.

  • Q : Use Finite-State Space Abstractions Use

    Use Finite-State Space Abstractions: In order to successfully apply explicit-state model checking, defects must be detectable in a sufficiently small state space. This can be achieved either by means of heuristics that constrain the way the state spac

  • Q : What is Random Access Memory Random

    Random Access Memory: Random access memory, or RAM, is the memory whose contents are simply accessible to the processing components of a computer. In specific, the time it takes to read and write to a particular portion of the memory does not based on

  • Q : What is an Object Object : It is an

    Object: It is an instance of a particular class. In common, any number of objects might be constructed from a class definition. The class to which an object belongs states the common characteristics of all instances of that class. In those characteris

  • Q : Define Heap Abstractions Heap

    Heap Abstractions: The class abstractions that we discussed above are obtained by abstracting each field of base type. The number of instances of that particular class still needs to be bounded; this results in an under-approximation that is still use

  • Q : Computer science 1. Here is a short

    1. Here is a short program. It prints out the value of a variable "x". Ernie and Bert disagree about what will be printed: Ernie says, the value gets changed in "changeX" so it will print "7", and Bert says, no, when the function exits the changes get reversed and the value goes back to "5". Explain

  • Q : What is Round robin allocation Round

    Round robin allocation: It is an allocation of time slices which repeatedly cycles regarding a set of eligible threads in the fixed order.

  • Q : Define Livelock Livelock : It is a

    Livelock: It is a situation in which a thread waits to be notified of a condition however, on waking, finds that the other thread has inverted the condition another time. The primary thread is forced to wait again. Whenever this occurs for an indefini

  • Q : Define the term Critical section

    Critical section: It is a section of code in which there is potential for a race hazard. The critical sections made use of the synchronized statements or methods.

©TutorsGlobe All rights reserved 2022-2023.