【发布时间】:2021-01-09 06:34:42
【问题描述】:
#include <iostream>
#include <stdlib.h>
#define Pi 3.14159
using namespace std;
class Rectangle
{
public:
friend ostream &operator<<(ostream &output,const Rectangle &D)
{
output<<"length:"<<D.length<<endl<<"height:"<<D.height<<endl;
return output;
}
friend istream &operator>>(istream &input,const Rectangle &D)
{
input >> D.length >> D.height;
return input;
}
private:
double length;
double height;
};
错误在 [17,19]:no operator ">>" 匹配这些操作数 -- 操作数类型是:std::istream >> const double
我在网上搜索了很长时间。但是没有用。请帮助或尝试提供一些想法如何实现这一目标。 非常感谢您的回答。
【问题讨论】:
-
您没有将变量声明为要写入值的
const &。 -
const Rectangle &D表示您不能修改D或其成员。
标签: c++