gpt4 book ai didi

c++ - 使用声明和 const 重载

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:20:39 25 4
gpt4 key购买 nike

假设我在一个基类中有两个版本的 operator->(在 const 上重载)。如果我说

using Base::operator->;

在派生类中,我可以访问两个版本还是只能访问非常量版本?

最佳答案

与姓名隐藏相同的业务。全有或全无。使用声明 (7.3.3) 带来一个名称,而不是一个成员

ISO/IEC 14882 (2003), 7.3.3. 1/ A using-declaration introduces a name into the declarative region in which the using-declaration appears. That name is a synonym for the name of some entity declared elsewhere.

我鼓励你阅读 7.3.3,里面有一些微妙的东西。您不能使用声明模板,所有由您使用声明的名称引用的成员都必须是可访问的,这些名称与发现使用声明的 block 中的名称一起被视为重载解析(即它们不隐藏任何内容) ), 等等等等。

关于c++ - 使用声明和 const 重载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6997194/

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