- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
这个代码是UB吗?
struct A
{
void nonconst() {}
};
const A& a = A{};
const_cast<A&>(a).nonconst();
换句话说,(临时)对象最初是 const
吗?我已经仔细阅读了标准,但找不到答案,因此希望能引用相关部分的内容。
编辑: 对于那些说 A{}
不是 const
的人,那么你可以做 A{}.nonconst()
?
最佳答案
引用的初始化a
由 [dcl.init.ref]/5 给出(大胆的矿山):
Otherwise, if the initializer expression
- is an rvalue (but not a bit-field)[...]
then the value of the initializer expression in the first case and the result of the conversion in the second case is called the converted initializer. If the converted initializer is a prvalue, its type T4 is adjusted to type “cv1 T4” ([conv.qual]) and the temporary materialization conversion ([conv.rval]) is applied.
所以这意味着初始化引用的类型纯右值表达式,A{}
, 调整为 const A
.
然后 [conv.rval]状态:
A prvalue of type T can be converted to an xvalue of type T. This conversion initializes a temporary object ([class.temporary]) of type T.
因此绑定(bind)到引用的临时对象的类型与调整后的 prvalue
相同输入:const A
.
所以代码 const_cast<A&>(a).nonconst();
是未定义的行为。
关于c++ - 临时对象最初是 const 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55828305/
我有一个使用 Sinch SDK 和 CallKit 实现的 VOIP 应用程序。一切正常,除了设备插入耳机时。在后一种情况下,当通话开始时,音频仍通过设备的主扬声器路由。如果我在通话期间拔下并重
我需要将大量复杂(20 多个属性)对象过滤成多个子列表。要创建子列表,我有一个过滤器规范列表。要求是:a) 不允许一个项目成为两个子列表的一部分,并且 b) 必须能够在处理完成后获取所有未分割的项目。
我有一个简单的 .share-toggle 切换链接。当您点击它时,Facebook 评论插件应该会显示。它最初应该被 Conceal 问题是,如果我使用 css Conceal 它,然后单击切换按钮
我正在尝试制作一个功能类似于 android 市场的图库,您可以在其中滚动(左/右)以查看免费或付费应用程序等...还可以在布局中上下滚动。 到目前为止,我只是让它加载了两个布局,它们都有一个简单的“
大家好,我是网络开发的新手,最近刚刚完成我对网络设计的第一次尝试。我偶然发现了一个我找不到解决方案的问题。在 webkit-browsers 中,我的一个 ul-lists(导航)最初呈现在错误的位置
我遇到了这个问题。我在 ISP 上使用 Umbraco CMS 启动了一个 ASP.NET 网站。(这只是一个非常基本的信息网站。没什么特别的。) 但是,当我想要访问该网站时,第一个页面加载需要很长时
在我的 iPhone 应用程序中,我使用 UITabBarController 布置了三个选项卡。第一个选项卡(在应用启动时加载)使用本地数据加载,速度非常快。 虽然第二个选项卡从网络下载 XML 文
我有这样的风格: #cytoscape-container { width: 100%; height: 100%; margin: 0 aut
我在这里看到了几篇关于 SO 的帖子,但它们在功能和结构上过于具体,而我正在寻找的是我或任何人都可以在任何地方使用的更通用的东西。 我只需要有一个按钮,单击该按钮可以在 3 类之间循环。但如果出现必须
我在 http://www.raven.dima.neoturbine.net/ 有一个网页我正在努力。顶部导航在 IE 8、Firefox 3.6 和适用于 Android 的 Dolphin 浏览
我想将主机的用户/组与 docker 机器同步,以使(开发人员)能够编辑容器内部或外部的文件。有一些这样的想法:Handling Permissions with Docker Volumes这会创建
向通知列表/栏发布推送通知时,.contentText 和 .number 最初不显示(.ticker、.icon 和 .contentTitle 显示正常)。但是,在发布另一个通知(具有不同的 ID
我实现了以下 MKMapView 方法,该方法在添加注释后运行。我在 Interface Builder 中将我的 MKMapView map (parishMap) 设置为“显示用户位置”,并且在加
我是一名优秀的程序员,十分优秀!