很久以前发现的 vc2008 的一个bug(关于模板匹配)
2009-04-18 23:44
495 查看
使用操作符重载时,出现模板匹配错误,bug 的出现很简单,下面是代码:
#include <stdio.h> #include <string> struct A1 { template<class Ch, class Tr, class Al> void operator<<(std::basic_string<Ch, Tr, Al>& x) { printf("void operator<<(std::basic_string<Ch, Tr, Al>& x)/n"); } }; struct A2 { void operator<<(std::string& x) { printf("void operator<<(std::string& x)/n"); } }; struct B1 : A1 { using A1::operator<<; template<class T> void operator<<(T& x) { printf("void operator<<(T& x)/n"); } }; struct B2 : A2 { using A2::operator<<; template<class T> void operator<<(T& x) { printf("void operator<<(T& x)/n"); } }; int main(int argc, char* argv[]) { std::string s = "abc"; B1 b1; // 下面两行调用了不同的函数,为什么? // these two line call different function, why? b1 << s; b1.operator<<(s); printf("/n"); B2 b2; // OK, 完全正确 // OK, all right b2 << s; b2.operator<<(s); return 0; }
相关文章推荐
- 很久以前发现的 vc2008 的一个bug(关于模板匹配)
- 发现 ASP.Net 的一个关于"回车提交"的 Bug ? 必须多于一个 Text 域"回车提交",Server: ButtonX_Click 才能截获!
- 终于发现自己存在的一个问题:关于用不用VC创建对象的问题
- 发现Oracle11.2.0.1关于NLS_LENGTH_SEMANTICS的一个Bug
- 发现 ASP.Net 的一个关于"回车提交"的 Bug ? 必须多于一个 Text 域"回车提交",Server: ButtonX_Click 才能截获!
- 以前发现的一个MYSQL的BUG
- 发现.net 4关于编译匿名函数的一个BUG
- 关于google的gson-2.3.1.jar,发现一个奇怪的bug
- 想起来很久以前碰到的一个ATL BUG
- 在ASP.NET中,发现的关于string转换的一个小Bug
- VC 2008 一个 可能的BUG ,或者本人的无知,请有大侠解读一下
- 这个是不是vc2008编译器的一个bug?
- 一个关于xslt的模板匹配规则的问题
- iOS 关于在提交了APP等待审核之后,发现小Bug需要再提一个版本的说明
- 发现IE8一个关于下载office2007 docx文档的bug
- 发现 SqlHelper v3.1 的一个关于 InputOutput 参数的 Bug? v2.1 老版没错!
- 今天非常高兴,解决了一个关于java类转json时有关联对象而且困扰我很久的BUG
- 发现 SqlHelper v3.1 的一个关于 InputOutput 参数的 Bug? v2.1 老版没错!
- 今天发现了JBuilder 2006 一个BUG,关于资源文件重构后的BUG
- 在AutoCAD 2008发现了一个动态块的BUG