問(wèn)題描述
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一>.
我假設(shè)第二個(gè)和第三個(gè)承諾"指的是類名和構(gòu)造函數(shù),但我無(wú)法弄清楚第一個(gè)的含義.我確信它不是指命名空間,因?yàn)樵撁Q不同.我已經(jīng)看到在示例中兩次使用了范圍解析運(yùn)算符,但那些是指嵌套的命名空間.
I assume that the second and the third "Commitment" refer to the class name and constructor, but I can't figure out the meaning of the first. I am sure that it does not refer to the namespace because that name is different. I have seen the scope resolution operator being used twice in examples, but those refer to nested namespaces.
推薦答案
在 C++ 中,類具有將其名稱注入其作用域的功能 ([class]/2):
In C++ classes have the feature of having their name injected into their scope ([class]/2):
class-name 也插入到類本身的作用域中;這被稱為 injected-class-name.出于訪問(wèn)目的檢查,injected-class-name 被視為公共會(huì)員名.
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
命名類本身,而在其他上下文中命名為 c'tor.只有最后一個(gè) Commitment(
,您打開(kāi)括號(hào)的地方,才開(kāi)始 c'tor 定義.
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.
它看起來(lái)可能更糟:
struct foo {
foo();
};
foo::foo::foo::foo() = default;
您可以看到有效的 C++ Live.
Which you can see is valid C++ Live.
這篇關(guān)于范圍解析運(yùn)算符被使用兩次的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!