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 : What is Lexicographic ordering

    Lexicographic ordering: It is the ordering of words as they would be easily found in a dictionary. It must be noted that dissimilar locales order identical looking words according to their own conventions - this exerts, in specific, to accented charac

  • Q : Explain Model-view pattern Model-view

    Model-view pattern: It is a pattern in which the representation of data (that is, the model) is kept separate from its visualization (that is, the view). These decoupling makes it simpler to change the underlying data representation, or give multiple

  • Q : OCIW32 dll error Normal 0 false false

    Normal 0 false false

  • Q : Scripting Language Programming

    Hi Assignment Team, Please find attachment of my assignment. Please advise if there is any unclear information Regards, King

  • Q : Define Little-endian Little-endian : It

    Little-endian: It is a common difference among machines is the order in which they store up the individual bytes of multi-byte numerical data. The little-endian machine stores the lower-order bytes prior to the higher-order bytes.

  • Q : Kernel Mode Illustrate what are the

    Illustrate what are the different functions of Kernel Mode, interrupts and system calls?

  • Q : Benefit from JavaIDL Why did Java

    Why did Java benefit from the development of JavaIDL?

  • Q : Define the term Constant Define the

    Define the term Constant: A variable whose value might not be changed. In Java, such are implemented by the final variables.

  • Q : Limit the Use of Pre-processor

    Limit the Use of Pre-processor Directives: The C pre-processor is powerful, but unrestricted use of it can lead to code that is hard to understand and analyze. Limit its use to inclusion of header files and simple macro definitions. Avoid features suc

©TutorsGlobe All rights reserved 2022-2023.