gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 15:51:50 30 4
gpt4 key购买 nike

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 上遇到这个函数定义.

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

最佳答案

在 C++ 中,类具有将其名称注入(inject)其作用域的特性 ([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 命名类本身,而在其他情况下命名 c'tor。只有最后一个 Commitment(,您打开括号的地方,开始 c'tor 定义。

它看起来更糟:

struct foo {
foo();
};

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

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

关于c++ - 范围解析运算符被使用两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47575074/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com