#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
 
出错提示这个,找不到重载符号<<,为什么?

解决方案 »

  1.   

    hugeintostream& hugeint::operator<<(ostream &out,hugeint &x)
    {   
             out<<x.ss;
    return out;
    }
      

  2.   

    编译器错误 C2593“operator identifier”不明确
    为重载运算符定义了多个可能的运算符。
    可能的解决方案 
    对一个或多个实际参数使用显式转换。 
    示例
    // 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
      

  3.   

    呵呵楼上说的对!
    也可以放在CLASS里
      

  4.   

    using namespace std;
    后面加这个
    class hugeint;
    extern ostream& operator<<(ostream&,const hugeint&);
    就可以了,呵