编译出现error C2678: 二进制“>>”: 没找到接受“std:istream”类型的左操作数的运算符(或没有可接受的转换),求指教
编译出现error C2678: 二进制“>>”: 没有找到接受“std::istream”类型的左操作数的运算符(或没有可接受的转换),求指教啊
写了个运算符重载的函数,编译的时候出现了错误: error C2678: 二进制“>>”: 没有找到接受“std::istream”类型的左操作数的运算符(或没有可接受的转换),
代码
------解决方案--------------------
写了个运算符重载的函数,编译的时候出现了错误: error C2678: 二进制“>>”: 没有找到接受“std::istream”类型的左操作数的运算符(或没有可接受的转换),
代码
#ifndef _AAA_
#define _AAA_
#include <iostream>
class plural
{
private:
int m_nReal;
int m_nImaginary;
public:
plural();
plural(int nReal, int nImaginary);
plural operator+(const plural &b);
plural operator-(const plural &b);
plural operator*(const plural &b);
friend plural operator*(int n, const plural &b);
friend std::ostream & operator<<(std::ostream &os, plural &b);
friend std::istream & operator>>(std::istream &is, const plural &b);
};
#endif
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#include "mytime.h"
plural::plural()
{
m_nImaginary = 0;
m_nReal = 0;
}
plural::plural(int nReal, int nImaginary)
{
m_nImaginary = nImaginary;
m_nReal = nReal;
}
plural plural::operator*(const plural &b)
{
plural temp;
temp.m_nImaginary = this->m_nImaginary * b.m_nImaginary;
temp.m_nReal = this->m_nReal * b.m_nImaginary;
return temp;
}
std::istream & operator>>(std::istream &is, const plural &b)
{
//std::cout<<"Imaginary:";
if (is >> b.m_nImaginary)
{
cout <<"real:";
is >> b.m_nReal;
}
return is;
}
std::ostream & operator<<(std::ostream &os, plural &b)
{
os<<'('<<b.m_nReal<<','<<b.m_nImaginary<<"i)"<<endl;
return os;
}
plural operator*(int n, const plural &b)
{
plural temp;
temp.m_nImaginary = b.m_nImaginary * n;
temp.m_nReal = b.m_nReal * n;
return temp;
}
int main()
{
plural a(3, 4);
plural temp;
cout<<a;
}
------解决方案--------------------
friend std::ostream & operator<<(std::ostream &os, const plural &b);
friend std::istream & operator>>(std::istream &is, plural &b);