范围解析运算符被两次使用 [英] Scope resolution operator being used twice

查看:105
本文介绍了范围解析运算符被两次使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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 上遇到了此函数定义a>.

I just encountered this function definition on GitHub.

我假设第二个和第三个"Commitment"是指类名和构造函数,但是我不知道第一个的含义.我确信它不会引用名称空间,因为该名称是不同的.我已经看到范围解析运算符在示例中被使用了两次,但是它们引用了嵌套的名称空间.

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 ++中,类具有将其名称注入其作用域的功能(

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

类名也被插入到类本身的作用域中; 这就是 injected-class-name .出于访问目的 检查,将 injected-class-name 视为公开 会员名称.

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定义.

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.

它看起来可能更糟:

struct foo {
    foo();
};

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

您会看到有效的C ++ 实时 .

Which you can see is valid C++ Live.

这篇关于范围解析运算符被两次使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆