一例奇怪的编译错误(VC6)

思房话

思房话

2016-02-19 18:41

今天图老师小编要跟大家分享一例奇怪的编译错误(VC6),精心挑选的过程简单易学,喜欢的朋友一起来学习吧!

一例奇怪的编译错误(VC6)

VC6 编译下段代码会报错.
将出错行
    if (mmm.end() == itr)        // ERROR
改写为
    if (itr == mmm.end())        // OK
就可通过.

(g++可以通过.)

/**//*
     error C2679: binary '==' : no operator defined which takes a right-hand operand of type 'class std::_Treeint,struct std::pairint const ,int,struct std::mapint,int,struct std::lessint,class std:
:allocatorint ::_Kfn,struct std::lessint,class std::allocatorint ::const_iterator' (or there is no acceptable conversion)
 
*/

#pragma warning(disable:4786)

#include map

(本文来源于图老师网站,更多请访问https://m.tulaoshi.com/bianchengyuyan/)

typedef std::mapint, int MYMAP;

(本文来源于图老师网站,更多请访问https://m.tulaoshi.com/bianchengyuyan/)

int main(int argc, char* argv[])
...{
    MYMAP mmm;
    MYMAP::const_iterator itr = mmm.find(1234);
    // if (mmm.end() == itr)    ERROR!!! (VC6)
    // if (itr == mmm.end())    OK
    if (mmm.end() == itr)
        return 123;
    return 0;
}

粗略地分析是map.end()返回的是iterator类型,
而iterator::operator==(const_iterator)没有定义.

将map.end()强制为const_iterator也可以通过.

展开更多 50%)
分享

猜你喜欢

一例奇怪的编译错误(VC6)

编程语言 网络编程
一例奇怪的编译错误(VC6)

最常见的20种VC++编译错误信息

编程语言 网络编程
最常见的20种VC++编译错误信息

s8lol主宰符文怎么配

英雄联盟 网络游戏
s8lol主宰符文怎么配

VC6几个技巧

编程语言 网络编程
VC6几个技巧

VC6下编译进Ring0代码的疑惑

编程语言 网络编程
VC6下编译进Ring0代码的疑惑

lol偷钱流符文搭配推荐

英雄联盟 网络游戏
lol偷钱流符文搭配推荐

Word2003中隐含模块编译错误

word
Word2003中隐含模块编译错误

WIN2000下使用SQL Server错误一例

SQLServer
WIN2000下使用SQL Server错误一例

lolAD刺客新符文搭配推荐

英雄联盟
lolAD刺客新符文搭配推荐

使用MVC模型的几个常见误区

使用MVC模型的几个常见误区

但愿你的记忆中有过我

但愿你的记忆中有过我
下拉加载更多内容 ↓