baidu_24736703
Kobe___Bryant
2016-05-04 11:08

碰到了一个短语c++操作符重载的问题

我在这个程序中重载>>操作符,报出了如下错误:
Error 1 error C2678: binary '>>' : no operator found which takes a left-hand operand of type 'std::istream' (or there is no acceptable conversion)
Error 2 3 IntelliSense: no operator ">>" matches these operands
operand types are: std::istream >> double
代码如下:
std::istream & operator>>(std::istream & is, Complex0 & c)
{
std::cout << "Please enter a: ";
is >> c.get_a();//这里报错
std::cout << "Please enter b: ";
is >> c.get_b();//这里报错
return is;
}
在类中声明如下:
friend std::istream & operator>>(std::istream & is, Complex0 & c);
求大神解释一下,并希望大神能够给出正确解决办法,感激不尽!!

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

3条回答