What Does the ": :" Mean in C++?

What Does the ": :" Mean in C++?

What does this symbol mean?

AirlineTicket::AirlineTicket()
2

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

0

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

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Sarah Jenkins
Author

Sarah Jenkins

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.