范围解析运算符被使用两次
Scope resolution operator being used twice
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));
}
我刚刚在 GitHub 上遇到这个函数定义。
我假设第二个和第三个"Commitment"指的是class名称和构造函数,但我无法弄清楚第一个的含义。我确信它没有引用名称空间,因为该名称不同。我已经看到范围解析运算符在示例中被使用了两次,但那些引用了嵌套的名称空间。
在 C++ 中 classes 具有将其名称注入其范围的功能 ([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.
并且您显示的代码片段使用了它。在某些情况下 Commitment::Commitment
命名为 class 本身,而在其他情况下命名为 c'tor。只有最后一个 Commitment(
,您打开括号的地方开始 c'tor 定义。
而且看起来可能更糟:
struct foo {
foo();
};
foo::foo::foo::foo() = default;
你可以看到这是有效的 C++ Live.
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));
}
我刚刚在 GitHub 上遇到这个函数定义。
我假设第二个和第三个"Commitment"指的是class名称和构造函数,但我无法弄清楚第一个的含义。我确信它没有引用名称空间,因为该名称不同。我已经看到范围解析运算符在示例中被使用了两次,但那些引用了嵌套的名称空间。
在 C++ 中 classes 具有将其名称注入其范围的功能 ([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.
并且您显示的代码片段使用了它。在某些情况下 Commitment::Commitment
命名为 class 本身,而在其他情况下命名为 c'tor。只有最后一个 Commitment(
,您打开括号的地方开始 c'tor 定义。
而且看起来可能更糟:
struct foo {
foo();
};
foo::foo::foo::foo() = default;
你可以看到这是有效的 C++ Live.