41

What does this symbol mean?

AirlineTicket::AirlineTicket()
Mateusz Piotrowski
  • 8,029
  • 10
  • 53
  • 79
Milad Sobhkhiz
  • 1,109
  • 4
  • 13
  • 26
  • 2
    @Paul R: Exactly. Here's the book list: http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list – Fred Larson Mar 17 '11 at 21:42
  • 15
    @PaulR Not everyone who arrives upon this question is looking to learn C++. I, for example, just happened to be skimming some C++ code and wanted to get the general idea of what the program is doing and needed a quick reference :) – Ebony Maw Dec 16 '18 at 18:34

4 Answers4

54

:: 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.

Erik
  • 88,732
  • 13
  • 198
  • 189
16

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

maerics
  • 151,642
  • 46
  • 269
  • 291
3

It declares a namespace. So in AirlineTicket:: you can call all public functions of the AirlineTicket class and AirlineTicket() is the function in that namespace (in this case the constructor).

Benedikt Bergenthal
  • 495
  • 1
  • 7
  • 20
0

AirlineTicket is like a namespace for your class. You have to use it in the implementation of the constructor.

Chris
  • 619
  • 2
  • 9
  • 18