标题:重载输入输出运算符的问题
取消只看楼主
骇客
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2004-11-9
 问题点数:0 回复次数:1 
重载输入输出运算符的问题

#include<iostream> using namespace std; class OpoverClass { friend ostream& operator<<(ostream&,const OpoverClass&); friend istream& operator>>(istream&,OpoverClass&); public: OpoverClass operator+ (const OpoverClass&) const; OpoverClass operator* (const OpoverClass&) const; OpoverClass (int i=0,int j=0){a=i;b=j;};

int a; int b; };

ostream& operator<<(ostream& osObject,const OpoverClass& right) { osObject<<"("<<right.a<<","<<right.b<<")"; return osObject; }

istream& operator>>(istream& isObject,OpoverClass& right) { isObject>>right.a>>right.b; return isObject; }

OpoverClass OpoverClass::operator *(const OpoverClass& right) const { OpoverClass temp; temp.a=a*right.a; temp.b=b*right.b; return temp; }

OpoverClass OpoverClass::operator +(const OpoverClass& right) const { OpoverClass temp; temp.a=a+right.a; temp.b=b+right.b; return temp; }

int main() { OpoverClass u(23,46); OpoverClass v; cout<<"u="<<u<<endl; cout<<"Enter two integers:"; cin>>v; cout<<endl; cout<<"u+v="<<u+v<<endl; cout<<"u*v="<<u*v<<endl; return 0; }

请大家帮忙看下错误:D:\c++\vdgfd\vfdf.cpp(51) : error C2593: 'operator <<' is ambiguous D:\c++\vdgfd\vfdf.cpp(53) : error C2593: 'operator >>' is ambiguous D:\c++\vdgfd\vfdf.cpp(55) : error C2593: 'operator <<' is ambiguous D:\c++\vdgfd\vfdf.cpp(56) : error C2593: 'operator <<' is ambiguous Error executing cl.exe.

vfdf.obj - 4 error(s), 0 warning(s)

搜索更多相关主题的帖子: 运算符 OpoverClass operator const 
2004-12-26 14:52
骇客
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2004-11-9
得分:0 
对,我是用C++ Builder 6,我也看不懂3楼斑竹所说的,好深奥啊
2004-12-30 20:55



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-10072-1-1.html




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

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