#include<iostream>
#include<string>
#include<math.h>
#include<stdlib.h>
using namespace std;
class hugeint
{
friend ostream& operator<<(ostream &out,hugeint &x);
};ostream& operator<<(ostream &out,hugeint &x)
{
out<<x.ss;
return out;
}void main()
{
hugeint a,b,c;
a="7448";
b="-557777777777777";
c=a+b;
cout<<c<<endl;
}
error C2593: 'operator <<' is ambiguous
出错提示这个,找不到重载符号<<,为什么?
#include<string>
#include<math.h>
#include<stdlib.h>
using namespace std;
class hugeint
{
friend ostream& operator<<(ostream &out,hugeint &x);
};ostream& operator<<(ostream &out,hugeint &x)
{
out<<x.ss;
return out;
}void main()
{
hugeint a,b,c;
a="7448";
b="-557777777777777";
c=a+b;
cout<<c<<endl;
}
error C2593: 'operator <<' is ambiguous
出错提示这个,找不到重载符号<<,为什么?
解决方案 »
- GDI+ 打开600DPI的JPEG文件失败,楼下秒
- 调用窗口的同时更换其中的位图
- 再一次请教VC++6.0串口通信问题
- 指针转换问题
- 需要vckbase 5周年精华光盘的请留下联系方式:QQ,MSN或者EMail
- 连接mysql数据库事出现“未找到提供程序,可能程序未正确安装”错误,有人碰到过吗?
- 如何在程序中等待一段时间后再继续执行?
- 关于软件维护,怎样找出他人程序的BUG?(0xdddddddd内存不能READ)
- 虽然很少得到回复,但我还是报最后一线希望提出一个关于重画的问题...
- 请问那里有<<Advanced Windows>>的电子版下载?最好是中文版。
- 如何在控制台程序中加入MFC支持
- 从网上找来的一个OPENGL基础教程上的第一个例子。。。
{
out<<x.ss;
return out;
}
为重载运算符定义了多个可能的运算符。
可能的解决方案
对一个或多个实际参数使用显式转换。
示例
// C2593.cpp
struct A {};
struct B : A {};
struct X {};
struct D : B, X {};
void operator+( X, X );
void operator+( A, B );
D d;
int main()
{
d + d; // C2593, D has an A, B, and X
(X)d + (X)d; // OK, uses operator+( X, X )
}
可能的原因
使用 CArchive 对象序列化浮点变量。编译器将 << 运算符标识为不明确的。CArchive 可序列化的唯一基元 C++ 类型是固定大小的类型 BYTE、WORD、DWORD 和 LONG。为进行序列化,所有 integer 类型都必须转换为这些类型之一。必须使用 CArchive::Write() 成员函数将浮点类型存档。
下面的示例说明如何将浮点变量 (f) 存档到 ar 存档中:
//C2593a.cpp
ar.Write(&f, sizeof( float )); //C2593
也可以放在CLASS里
后面加这个
class hugeint;
extern ostream& operator<<(ostream&,const hugeint&);
就可以了,呵