Scope resolution operator

Scope resolution operator

In computer programming, scope is an enclosing context where values and expressions are associated. The scope resolution operator helps to identify and specify the context to which an identifier refers. The specific uses vary across different programming languages with the notions of scoping.

Contents

C++

The scope resolution operator (::) in C++ is used to define the already declared member functions (in the header file with the .hpp or the .h extension) of a particular class. In the .cpp file one can define the usual global functions or the member functions of the class. To differentiate between the normal functions and the member functions of the class, one needs to use the scope resolution operator (::) in between the class name and the member function name i.e. ship::foo() where ship is a class and foo() is a member function of the class ship. The other uses of the resolution operator is to resolve the scope of a variable when the same identifier is used to represent a global variable, a local variable, and members of one or more class(es). If the resolution operator is placed between the class name and the data member belonging to the class then the data name belonging to the particular class is referenced. If the resolution operator is placed in front of the variable name then the global variable is referenced. When no resolution operator is placed then the local variable is referenced.

Example

#include <iostream>
 
// Without this using statement cout below would need to be std::cout
using namespace std; 
 
int n = 12; // A global variable
 
int main() {
  int n = 13; // A local variable
  cout << ::n << endl; // Print the global variable: 12
  cout << n   << endl; // Print the local variable: 13
}

PHP

In PHP, the scope resolution operator is also called Paamayim Nekudotayim (Hebrew: פעמיים נקודתיים‎, pronounced [paʔaˈmajim nəkudoˈtajim]), which means "twice colon" or "double colon" in Hebrew.

The name was introduced in the Israeli-developed[1] Zend Engine 0.5 used in PHP 3. Although it has been confusing to many developers who don't speak Hebrew, it is still being used in PHP 5, as in this sample error message:

$ php -r '::'
Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM

A similar error can also occur where no scope resolution operator is present. For example, attempting to check whether a constant is empty() triggers this error:

$ php -r "define('foo', 'bar'); if (empty(foo)) echo 'empty';"
Parse error: syntax error, unexpected ')', expecting T_PAAMAYIM_NEKUDOTAYIM

References


Wikimedia Foundation. 2010.

Игры ⚽ Поможем сделать НИР

Look at other dictionaries:

  • Paamayim Nekudotayim — (pronounced|paʔamajim nəkudotajim) is the official name for the Scope Resolution Operator (::) in PHP. It means twice colon or double colon in Hebrew. Nekudotayim (נקודתיים) means colon ; it comes from nekuda (IPA: IPA| [nəkuda] ), point or dot …   Wikipedia

  • C++ — The C++ Programming Language, written by its architect, is the seminal book on the language. Paradigm(s) Multi paradigm:[1] procedural …   Wikipedia

  • Colon (punctuation) — Colon Punctuation apostrophe ( ’ …   Wikipedia

  • Ch (computer programming) — In computing, Ch (  /ˌsiːˈ …   Wikipedia

  • Method overriding — Method overriding, in object oriented programming, is a language feature that allows a subclass or child class to provide a specific implementation of a method that is already provided by one of its superclasses or parent classes. The… …   Wikipedia

  • Perl-Modul — Mechanismus der Einbindung und Verwendung von Perl Modulen Ein Perl Modul ist eine separate Komponente eines Computerprogramms, das in Perl geschrieben wurde. Ein Modul besitzt seinen Quellcode in einer Moduldatei der Endung .pm, die wiederum ein …   Deutsch Wikipedia

  • Operators in C and C++ — This is a list of operators in the C and C++ programming languages. All the operators listed exist in C++; the fourth column Included in C , dictates whether an operator is also present in C. Note that C does not support operator overloading.… …   Wikipedia

  • Economic Affairs — ▪ 2006 Introduction In 2005 rising U.S. deficits, tight monetary policies, and higher oil prices triggered by hurricane damage in the Gulf of Mexico were moderating influences on the world economy and on U.S. stock markets, but some other… …   Universalium

  • Borel functional calculus — In functional analysis, a branch of mathematics, the Borel functional calculus is a functional calculus (that is, an assignment of operators from commutative algebras to functions defined on their spectrum), which has particularly broad… …   Wikipedia

  • Oscilloscope — This article is about current oscilloscopes, providing general information. For history of oscilloscopes, see Oscilloscope history. For detailed information about various types of oscilloscopes, see Oscilloscope types. Illustration showing the… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”