Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the "::" mean in C++?

Tags:

c++

What does this symbol mean?

AirlineTicket::AirlineTicket() 
like image 473
Milad Sobhkhiz Avatar asked Mar 17 '11 21:03

Milad Sobhkhiz


People also ask

Why is :: used in C++?

The scope resolution operator ( :: ) is used for several reasons. For example: If the global variable name is same as local variable name, the scope resolution operator will be used to call the global variable. It is also used to define a function outside the class and used to access the static variables of class.

What is the difference between :: and in C++?

The :: operator is known as the scope resolution operator, and it is used to get from a namespace or class to one of its members. The . and -> operators are for accessing an object instance's members, and only comes into play after creating an object instance. You use .

What does this symbol mean C?

Copyright: ©. When you write a "C" with a circle around the letter, or use the word "copyright," you are giving notice to the public that the work is copyrighted and that you are the owner of the work.


Video Answer


2 Answers

:: is the scope resolution operator - used to qualify names. In this case it is used to separate the class AirlineTicket from the constructor AirlineTicket(), forming the qualified name AirlineTicket::AirlineTicket()

You use this whenever you need to be explicit with regards to what you're referring to. Some samples:

namespace foo {   class bar; } class bar; using namespace foo; 

Now you have to use the scope resolution operator to refer to a specific bar.

::foo::bar is a fully qualified name.

::bar is another fully qualified name. (:: first means "global namespace")

struct Base {     void foo(); }; struct Derived : Base {     void foo();     void bar() {        Derived::foo();        Base::foo();     } }; 

This uses scope resolution to select specific versions of foo.

like image 169
Erik Avatar answered Oct 08 '22 02:10

Erik


In C++ the :: is called the Scope Resolution Operator. It makes it clear to which namespace or class a symbol belongs.

like image 33
maerics Avatar answered Oct 08 '22 02:10

maerics