| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 815 人关注过本帖
标题:[讨论]VC++中的bug
只看楼主 加入收藏
幽园香客
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:231
专家分:142
注 册:2006-2-27
结帖率:50%
收藏
 问题点数:0 回复次数:6 
[讨论]VC++中的bug
各位大哥,小弟在编程过程中,碰到以下错误:error C2593: 'operator <<' is
ambiguous。我查了一下MSDN,发现里面提示说:Microsoft has confirmed this to be a bug in
the Microsoft products listed at the beginning of this article. We are
researching this bug and will post new information here in the
Microsoft Knowledge Base as it becomes
available。我尝试着按照里面所说的对操作符<<进行重定义,却发现给定的例子都无法通过编译,也是遇到同样的错误,不知道错在哪里。不知道各位大哥是否也遇到同样的情况,你们又是如何解决的?小弟在这里谢过先!


[此贴子已经被作者于2006-3-9 9:36:54编辑过]

搜索更多相关主题的帖子: bug Microsoft 定义 操作符 operator 
2006-03-09 09:10
myajax95
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:30
帖 子:2978
专家分:0
注 册:2006-3-5
收藏
得分:0 
把出错的那行程序和要'&lt;&lt;'得变量类型贴出来一下吧。

http://myajax95./
2006-03-09 15:46
幽园香客
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:231
专家分:142
注 册:2006-2-27
收藏
得分:0 
谢过先,呵呵
这个是VC++ MSDN里提供的例子:
//Sample.cpp
// Compiler Options : /GX
//#define WORKAROUND
//Uncomment this line to workaround
#include<iostream>
using namespace std;

#ifdef WORKAROUND
std::ostream& operator<<(std::ostream& os, __int64 i )
{
char buf[20];
sprintf(buf,"%I64d", i );
os << buf;
return os;
}

#endif
int main()
{
__int64 i64;
cout << i64 ;//这是提示错误的地方,
//这是编译提示的错误D:\工程\VC_workspace\text\sample.cpp(23) : error C2593: 'operator <<' is ambiguous
return 0;
}
自己的程序是这样的:
// Demonstrate the multithreaded garbage collector.
#include <iostream>
#include <new>
#include "gcthrd.h"
using namespace std;

// A simple class for load testing GCPtr.
class LoadTest
{
//int a, b;
public:
double n[100000]; // just to take-up memory
double val;
int a, b;
LoadTest() { a = b = 0; }
LoadTest(int x, int y)
{
a = x;
b = y;
val = 0.0;
}
friend ostream &operator<<(ostream &strm, LoadTest &obj);

};

// Create an insertor for LoadTest.
ostream &operator<<(ostream &strm, LoadTest &obj)
{
strm << "(" << obj.a << " " << obj.b << ")";
return strm;
}

int main()
{
GCPtr<LoadTest> mp;
int i;
for(i = 1; i < 2000; i++) {
try {
mp = new LoadTest(i, i);
if(!(i%100))
cout << "gclist contains " << mp.gclistSize() << " entries.\n";
}
catch(bad_alloc xa)
{
// For most users, this exception won't
// ever occur.
cout << "Last object: " << *mp << endl; //这是出错的地方
// 编译提示的错误:D:\工程\VC_workspace\GCPtr\main.cpp(46) : error C2593:'operator <<' is ambiguous
cout << "Length of gclist: " << mp.gclistSize() << endl;
}
}
return 0;
}

我在想,是不是编译环境的问题,也不知道该如何去设置。

[此贴子已经被作者于2006-3-9 16:17:12编辑过]


做个有用的人!
2006-03-09 16:00
myajax95
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:30
帖 子:2978
专家分:0
注 册:2006-3-5
收藏
得分:0 
没用过__int64,不知道为什么一定要用这么个类型,整数长了一点不知有什么好处,MSDN的help说
The __int64 type has no ANSI equivalent.
大概这类型没法用<<,
在VC++下就把下面这行字的"//"去掉吧
//#define WORKAROUND

http://myajax95./
2006-03-09 16:29
幽园香客
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:231
专家分:142
注 册:2006-2-27
收藏
得分:0 
对于ostream类来说,VC++里的&lt;&lt;与之_int64不匹配,所以才会出现以上的问题,解决的办法就是自己定义一个
operator,然后MSDN就提供了将如何将_int64的变量传递给ostream&lt;&lt;操作符的例子,可是问题就是,它给的例子(上面
的第一例子)还是出现相同的错误。用_int64有什么好处我也不清楚。呵呵!

做个有用的人!
2006-03-10 15:25
high20033763
Rank: 1
等 级:新手上路
帖 子:85
专家分:0
注 册:2006-2-13
收藏
得分:0 
感觉有时候把MSDN的例子直接搬过来编译,老是出错,不知为什么??
2006-03-12 21:51
programfan
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2006-3-14
收藏
得分:0 

2006-03-14 22:56
快速回复:[讨论]VC++中的bug
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015326 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved