Scope resolution operator being used twice

In C++ classes have the feature of having their name injected into their scope ([class]/2):

The class-name is also inserted into the scope of the class itself;
this is known as the injected-class-name. For purposes of access
checking, the injected-class-name is treated as if it were a public
member name.

And the code snippet you showed makes use of it. In certain contexts Commitment::Commitment names the class itself, and in others names the c’tor. Only the last Commitment(, where you open the parentheses, begins the c’tor definition.

And it can look much much worse:

struct foo {
    foo();
};

foo::foo::foo::foo() = default;

Which you can see is valid C++ Live.

Leave a Comment