wyn0222 2016-05-08 07:27 采纳率: 50%
浏览 1382
已采纳

C++重载运算符“<<”和“>>”出现错误

主函数中用<<>时
出现错误
no operator defined which takes a right-hand operand of type 'class vsctor' (or there is no acceptable conversion)

#include
using namespace std;
class vsctor
{
public:
vsctor(int z1=0,int z2=0,int z3=0);
void set(int z1,int z2,int z3);
void get(int& a,int& b,int& c) const;
//ostream& operator<<(ostream& os,const vsctor& v);
//istream& operator>>(istream& is,vsctor& v);
private:
int a,b,c;
};
main()
{
int z1,z2,z3,x1,x2,x3,y1,y2,y3;
vsctor v1(1,1,1);
vsctor v2(2,2,2);
cout< vsctor v;
cin>>v;
cout< }
vsctor::vsctor(int z1,int z2,int z3):a(z1),b(z2),c(z3)
{}
void vsctor::set(int x1,int x2,int x3)
{
a=x1;b=x2;c=x3;
}
void vsctor::get(int& z1,int& z2,int& z3) const
{
z1=a;z2=b;z3=c;
}
ostream& operator {
int z1,z2,z3;
v.get(
z1,z2,z3);
os return os;
}
istream& operator>>(istream& is,vsctor& v)
{
int z1,z2,z3;
is>>z1>>z2>>z3;
v.set(z1,z2,z3);
return is;
}

  • 写回答

2条回答 默认 最新

  • 小灸舞 2016-05-08 12:11
    关注

    楼主贴一下代码吧,这样很难分析

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP