c++题目有个错误不知道怎么回事

c++题目有个错误不知道怎么回事
#include
#include
using namespace std;
class Rectangle
{
public:
Rectangle(int a1,int b1,int a2,int b2);
void area(int a1,int b1,int a2,int b2);
void output();
Rectangle();
private:
int ar;
};
Rectangle::Rectangle(int a1,int b1,int a2,int b2)
{
}
void area(int a1,int b1,int a2,int b2)//计算面积
{
ar=(-1)*(a1-a2)*(b1-b2);
}
void Rectangle::output()
{
cout
cynthyqueen 1年前 已收到1个回答 举报

兰子530 幼苗

共回答了19个问题采纳率:100% 举报

void area(int a1,int b1,int a2,int b2)//计算面积
{
ar=(-1)*(a1-a2)*(b1-b2);
}
这个函数是Rectangle类的一个成员函数,但是你的定义方法认为它是一个全局函数,所以不能识别类的私有变量
改成
void Rectangle::area(.)
{
}

1年前

10
可能相似的问题
Copyright © 2024 YULUCN.COM - 雨露学习互助 - 16 q. 0.019 s. - webmaster@yulucn.com