- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
这看起来像是一个编译器错误,但案例太简单了,我有点怀疑,所以我正在寻找确认。可使用 VS2010 和 VS2012 重现。下面的示例无法编译。给出此错误:
Error 1 error C2440: 'type cast' : cannot convert from 'ConvertibleToAny' to 'OtherType<_Ty>' test.cpp 40
如果将移动构造函数 OtherType(ThisType &&)
的位置移动到构造函数 OtherType( int )
上方,它会突然编译。
#include "stdafx.h"
#include <string>
using namespace std;
template<class _Ty>
struct OtherType
{
typedef OtherType<_Ty> ThisType;
OtherType()
{
}
OtherType( int )
{
}
// The move constructor
OtherType(ThisType && )
{
}
};
struct ConvertibleToAny
{
template <class AnyType>
operator AnyType()
{
return AnyType();
}
};
int _tmain(int argc, _TCHAR* argv[])
{
(OtherType<wstring>) ConvertibleToAny();
return 0;
}
这是错误还是预期的行为?如果是预期的,请引用 C++11 规范中的相关段落。我已经将此作为错误发布在 Microsoft Connect 上,click here to open it .
最佳答案
你的表情
(OtherType<wstring>) ConvertibleToAny()
是从用户定义的临时类型到用户定义类型的一元显式转换 (5.4),根据 5.4:4 解释为 static_cast
:
static_cast<OtherType<wstring>>(ConvertibleToAny())
根据 5.2.9:4 具有初始化临时变量 t
的有效性:
OtherType<wstring> t(ConvertibleToAny())
这是直接初始化 (8.5:15),因此 (8.5:16) OtherType
的所有单参数构造函数都按照规则参与重载决议在 13.3.1.3 中。
在 13.3:2 之后,int
和 move 构造函数都可用并且按照 13.3.2 是可行的,因此对于单个参数,我们有两个可能的隐式转换序列 (13.3.3.1):
ConvertibleToAny [temporary] -> int
ConvertibleToAny [temporary] -> OtherType<wstring> &&
在 13.3.3.1.2 之后,这些序列之间没有顺序,因此没有最佳可行函数,重载解析失败 (13.3:3),并且程序格式错误。
如果转换函数 (12.3.2) 为显式
(12.3.2:2),则仅考虑直接初始化。尽管隐式转换序列 (13.3.3.1) 是隐式转换 (4:3),因此涉及复制初始化,但 12.3.2:2 示例中标准的意图显然是在这种情况下应考虑显式转换函数;因此,重载决议似乎再次失败。
关于c++ - 移动构造函数在类中的位置/顺序很重要吗?模板转换运算符结合移动构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12364806/
什么是事物 事务是一种机制、一个操作序列,包含了一组数据库操作命令,并且把所有的命令作为一个整体一起向系统提交或撤销操作请求,即这组数据库命令要么都执行,要么都不执行。 事务是一个不可分割的工.作逻辑
什么是范式? 简言之就是,数据库设计对数据的存储性能,还有开发人员对数据的操作都有莫大的关系。所以建立科学的,规范的数据库是需要满足一些规范来优化数据数据存储方式。在关系型数据库中这些规范就可以称为范
什么是事物 事务是一种机制、一个操作序列,包含了一组数据库操作命令,并且把所有的命令作为一个整体一起向系统提交或撤销操作请求,即这组数据库命令要么都执行,要么都不执行。 事务是一个不可分割的工.作逻辑
什么是范式? 简言之就是,数据库设计对数据的存储性能,还有开发人员对数据的操作都有莫大的关系。所以建立科学的,规范的数据库是需要满足一些规范来优化数据数据存储方式。在关系型数据库中这些规范就可以称为范
我正在尝试修改网站的布局,但有时网站会使用 !important,有没有办法覆盖它?我似乎无法弄清楚如何在页面的 css 文件之后加载 css 内容脚本。 最佳答案 !important CSS 规则
这个问题在这里已经有了答案: How to override !important? (12 个答案) 关闭 9 年前。 我写了一些 html,并在第三方网站中注入(inject)了一些 css 样
好的,我在这里安装了一个 wordpress 主题(www.sullivansuccesscoaching.com/home ...我们需要/home,因为仍然有一个 index.html 隐藏了 w
我已经为我的 Wordpress 模板创建了一个覆盖原始 CSS 的自定义样式表。但是,在我的日历页面上,原始 CSS 具有使用 !important 声明设置的每个表格单元格的高度: td {hei
这个问题在这里已经有了答案: How to document deconstructed parameters with JsDoc (1 个回答) 关闭 5 年前。 我正在努力寻找对文档 ES6
我的网站使用 bootstrap 4 和我制作的 css 文件。 在这个 css 文件的底部,我放置了一些媒体查询: @media (max-width: 575px) { .address .c
可以将 background-position X 设置为 0 带有标志 !important 和背景位置 Y 不带 !important? 例如: background-position-x: 0
我只想在焦点状态下去掉下拉列表中的轮廓。看这张图 我尝试使用 !important 覆盖 Bootstrap ,但根本不起作用。只是检查开发工具,突然看到这个。 Bootstrap 也使用 !impo
这个问题在这里已经有了答案: How to override !important? (12 个答案) 关闭 1 年前。
发生了什么事?:我的 jQuery Accordion 的动画坏了。在关闭上一个选项卡之前短时间单击下一个选项卡后,它会显示之前打开的选项卡。动画也不滑动。 CSS:来自this answer /*
如何使用 javascript 或 CSS 覆盖样式“color: red”?我想让它成为“2px”而不是“1px”边框。 Lorem... 我无法向“div”添加类、id。这不
这个问题在这里已经有了答案: How to override !important? (12 个答案) 关闭 5 年前。
滚动有问题不想显示其内容,如果我这样做 #callCenter { position: fixed; z-index: 2411 !important; display: bl
序言 1、MySQL表操作(创建表,查询表结构,更改表字段等), 2、MySQL的数据类型(CHAR、VARCHAR、BLOB,等), 本节比较重要,对数据表数据进行查询操作,其中可能大
如何将!important添加到客户端包GWT中的gwt-image: 我有这个: @sprite .superButton{ gwt-image : 'superButton'; backg
请帮助我..我想验证表单并使用 ajax 发送。 验证没有 ''onsubmit="return validateForm(this);"'' 工作。 但是当表单正确时,它的发送表单(页面刷新..)请
我是一名优秀的程序员,十分优秀!