注册 登录
编程论坛 C++教室

程序编译错误, 求解!

yang400b 发布于 2012-06-15 16:35, 348 次点击
#include<iostream>
using namespace std;
class rectangle
{    public:
    void area(point t)
    {    cout<<(t.y1-t.y)*(t.x1-t.x)<<endl;  }
};
class point
{   friend rectangle;
    double x,y,x1,y1;
    public:
    point(double a,double b,double c,double d)
    {
        x=a; y=b; x1=c; y1=d;
    }
};
int main()
{  double a,b,c,d;
   cin>>a>>b>>c>>d;
   rectangle t1;
   point t2(a,b,c,d);
   t1.area(t2);
   return 0;
}
5 C:\Documents and Settings\Administrator\桌面\bj.cpp variable or field `area' declared void
5 C:\Documents and Settings\Administrator\桌面\bj.cpp expected `;' before '(' token
7 C:\Documents and Settings\Administrator\桌面\bj.cpp expected `;' before '}' token
9 C:\Documents and Settings\Administrator\桌面\bj.cpp a class-key must be used when declaring a friend
 C:\Documents and Settings\Administrator\桌面\bj.cpp In function `int main()':
22 C:\Documents and Settings\Administrator\桌面\bj.cpp 'class rectangle' has no member named 'area'
2 回复
#2
lonmaor2012-06-15 16:42
rectangle类用到point类型了,所以需要在之前定义一下。
#3
yang400b2012-06-15 17:43
OK谢谢!
1