编译错误 error C2451: “std::_Unforced”类型的条件表达式是非法的
part 1
编译器 vs2015 VC++。
完整的错误信息粘贴如下:
d:\program files (x86)\microsoft visual studio 14.0\vc\include\algorithm(43): error C2451: “std::_Unforced”类型的条件表达式是非法的
完整代码:
struct Bigger {
bool operator() (vector<string>::size_type lhs, vector<string>::size_type rhs) { // 第一个形参是型别是 Bug
return lhs > rhs;
}
}; void biggies(vector<string>& words, const vector<string>::size_type sz)
{
auto beg = words.begin();
while (beg != words.end())
{
auto temp =
find_if(beg, words.end(), bind(Bigger(), placeholders::_1, sz)); // 这里引发的错误
cout << *temp << " ";
beg = ++temp;
}
cout << endl;
}
出处:《C++ primer 5th》习题 14.40。
part 2 正文
意图:
调用函数对象 Bigger() 来处理 find_if() 算法遍历的两个参数,比较两者的大小关系。
错误代码:
struct Bigger {
bool operator() (vector<string>::size_type lhs, vector<string>::size_type rhs) { // 第一个形参是型别是 Bug
return lhs > rhs;
}
};
错误原因:
错误的地方在于 Bigger::operator() 的形参列表和 find_if() 的三个参数不符合。
Bigger::operator() (vector<string>::size_type, vector<string>::size_type)
与find_if()的第三个参数—— bind(Bigger(), placeholders::_1, sz) ——匹配的形参列表应该是:
Bigger::operator() (const string&, vector<string>::size_type)
如何改正:
struct Bigger {
bool operator() (const string& lhs, vector<string>::size_type rhs) {
return lhs.size() > rhs;
}
};
第一个参数改写成 const string& 型别。
(全文完)
编译错误 error C2451: “std::_Unforced”类型的条件表达式是非法的的更多相关文章
- Ubuntu12.04安装64位系统出现编译错误error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or dir
问题: Ubuntu12.04安装64位系统出现编译错误error while loading shared libraries: libz.so.1: cannot open shared obje ...
- VS2110。VC++编译错误"error LNK2005: 已经在 XXX.obj 中定义的问题"
有时候我们会在头文件当中定义一些全局变量或者全局函数,这种做法会比较方便,但有时候会出现“编译错误"error LNK2005: 已经在 XXX.obj 中定义的问题"的链接问题. ...
- Thrift-0.10.0 CenOS 7 编译错误 error: expected ')' before 'PRIu32'
Thrift-0.10.0 CenOS 7 编译错误 error: expected ')' before 'PRIu32' 在编译Thrift的时候,无论是Apache官网tar包,还是Github ...
- C++编译错误--C++连接redis:编译错误error C2371: “off_t”: 重定义;不同的基类型
编译错误:对于编译C++调用hiredis编译错误:error C2371: “off_t”: 重定义:不同的基类型,如下图: 可能的解决方案: 1. 因为hiredis预处理器定义了_OFF_T_D ...
- 编译错误error: invalid&nbsp…
昨天遇到一个莫名其妙的编译错误,以前没有见过,而且代码流程看起来也没有太多的奇异之处.后来忍无可忍,百度了下,发现别人也有遇到这个错误的,他的解决方法是:少了"}". 嘿嘿,我开始 ...
- bullet, iOS真机编译错误error: identifier or immediate expression expected解决方法
刚才发现c3dEngine2(http://git.oschina.net/wantnon2/c3dEngine2 或 https://github.com/wantnon2/c3dEngine2)的 ...
- Qt5.编译错误.error: C2338: The slot requires more arguments than the signal provides.
1.Qt563x86vs2015,遇到如下 编译错误: error: C2338: The slot requires more arguments than the signal provides. ...
- IAR编译错误Error[e16]: Segment ISTACK (size: 0xc0 align: 0) is too long for segment definition. At least 0x8 more bytes needed. The problem occurred while processing the segment
问题:个人使用的是IARV9.10编译CC2541的工程,没有做任何修改,直接编译出现如下错误 Error[e16]: Segment ISTACK (size: 0xc0 align: 0) is ...
- VC++编译错误error C2065: “HANDLE”: 未声明的标识符及添加winbase.h后提示winbase.h(243): error C2146: 语法错误: 缺少“;”(在标识符“Internal”的前面)的解决办法
问题描述: VC++程序编译时提示错误:error C2065: “HANDLE”: 未声明的标识符等众多错误提示,如下所示: error C2065: “HANDLE”: 未声明的标识符 error ...
随机推荐
- HDU-1011 Starship Troopers(树形dp)
Starship Troopers Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- docker daemon configuration
于 Docker的分层镜像,除了 aufs,docker还支持btrfs, devicemapper和vfs,你可以使用 -s 或 –storage-driver= 选项来指定相关的镜像存储.在Ubu ...
- Docker,docker-machine,docker-composer
https://docs.docker.com/engine/installation/mac/ Docker值得关注的特性文件系统隔离:每个进程容器运行在一个完全独立的根文件系统里.资源隔离:系统资 ...
- select.select的使用注意事项
1.select的一个缺点在于单个进程能够监视的文件描述符的数量存在最大限制,在Linux上一般为1024,不过可以通过修改宏定义甚至重新编译内核的方式提升这一限制. 2.select()所维护的存储 ...
- UITableView _endCellAnimationsWithContext崩溃
http://www.cocoachina.com/bbs/read.php?tid-315222.html 删除cell之前先把数据源也删除一条,直接删除cell会崩溃 下面是正确的姿势: cell ...
- java数据库三大范式
引用知乎网友@ 王红波的回答 一范式就是属性不可分割.属性是什么?就是表中的字段.不可分割的意思就按字面理解就是最小单位,不能再分成更小单位了.这个字段只能是一个值,不能被拆分成多个字段,否则的话,它 ...
- find a way to escape--hdu1593
题目链接 : http://acm.hdu.edu.cn/showproblem.php?pid=1593 找到二者角速度相等时水中人的R,在此之前二者保持在一条直线上,之后水中的人沿直线到岸边S点匀 ...
- 【虫师Python】第二讲:元素定位
一.六种定位方式 1.id 2.name 3.class name 4.tag name:定位标签 5.link text:定位一个链接,如果是中文,需要在代码文最前面加一句I话|:#coding=u ...
- mysql python pymysql模块 基本使用
我们都是通过MySQL自带的命令行客户端工具mysql来操作数据库,那如何在python程序中操作数据库呢? 这就用到了pymysql模块,该模块本质就是一个套接字客户端软件,使用前需要事先安装 pi ...
- MySQL · 功能分析 · 5.6 并行复制实现分析
背景 我们知道MySQL的主备同步是通过binlog在备库重放进行的,IO线程把主库binlog拉过去存入relaylog,然后SQL线程重放 relaylog 中的event,然而这种模式有一个问题 ...