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 : How authorities save their Private Keys

    How do certifying authorities save their Private Keys?

  • Q : Explain Magic number Magic number : It

    Magic number: It is a constant value with significance within a specific context. For example, the value 12 could mean numerous different things - the number of hrs you have worked today, the number of dollars you are payable by a friend, and so forth

  • Q : Define the synchronization objects

    Define the synchronization objects. Ansewr: A synchronization object is use to co-ordinate the execution of many threads.

  • Q : Define the term Scheduler Define the

    Define the term Scheduler: The portion of the Java Virtual Machine (abbreviated as JVM) which is responsible for managing the threads.

  • Q : What is Java What is Java: It is a

    What is Java: It is a portable high level programming language introduced by Sun Microsystems.

  • Q : Class and Object and explain diverse

    Q. Define class and object with example and explain diverse specifies.  

  • Q : Describe Multiple-boot options

    Multiple-boot options: The hardware configurations of several computers are capable to run various operating system and window manager combinations. A few systems permit a user to select which combination they wish to utilize during a specific session

  • Q : Define Parallel programming Parallel

    Parallel programming or parrelel computing is the concurrent use of multiple compute resources to resolve a specified problem. Parallel program always comprises of concurrently executing processes, problem decomposition relates to the manner in which

  • Q : Define Data type Data type : There are

    Data type: There are 8 primitive data types in Java; five of such symbolize numerical types of changeable range and precision - float, double, int, long and short. The remaining three are employed to symbolizing single-bit values (that is, Boolean), s

  • Q : Different services provided by DLR to

    Give details about the different services that are provided by DLR to CLR?

©TutorsGlobe All rights reserved 2022-2023.