范围解析运算符被使用两次

Elo*_*loy 10 c++ constructor namespaces class name-lookup

namespace libzerocoin {

//Commitment class
Commitment::Commitment::Commitment(const IntegerGroupParams* p,
                               const Bignum& value): params(p), contents(value) {
this->randomness = Bignum::randBignum(params->groupOrder);
this->commitmentValue = (params->g.pow_mod(this->contents, params->modulus).mul_mod(
                         params->h.pow_mod(this->randomness, params->modulus), params->modulus));
}
Run Code Online (Sandbox Code Playgroud)

我刚刚在GitHub上遇到过这个函数定义.

我假设第二个和第三个"承诺"引用了类名和构造函数,但我无法弄清楚第一个的含义.我确信它没有引用命名空间,因为该名称不同.我已经看到范例解析运算符在示例中被使用了两次,但那些引用了嵌套的命名空间.

Sto*_*ica 14

在C++类中,具有将其名称注入其范围([class]/2)的功能:

类名也被插入到类本身的范围; 这被称为注入类名.出于访问检查的目的,inject-class-name被视为公共成员名称.

您展示的代码段会使用它.在某些情况下Commitment::Commitment,该类本身的名称,以及其他名称中的c'tor.只有最后一个Commitment(打开括号的地方才会开始定义c'tor.

它可能看起来更糟糕:

struct foo {
    foo();
};

foo::foo::foo::foo() = default;
Run Code Online (Sandbox Code Playgroud)

您可以看到有效的C++ Live.