回 帖 发 新 帖 刷新版面

主题:帮忙看一下好吗

#include<iostream.h>
class point
{
public:
    point(double i,double j) {x=i,y=j;}
    virtual double area() const{return 0.0;}
private:
    double x,y;
};

class rectangle:public point
{
public:
    rectangle(int i,int j,int k,int,l);
    virtual double area() const{return w*h;}
private:
    double w,h;
};

rectangle::rectangle(double i,double j,double k,double l):point(i,j)
{
    w=k;h=l;
}
void fun(point &s)
{
    cout<<"area="<<s.area()<<endl;
}
void main()
{
    rectangle rec(3,5,15,25);
    fun(rec);
}

调试错误如下:
--------------------Configuration: text2 - Win32 Debug--------------------
Compiling...
aaa.cpp
D:\VC++6.0\MSDev98\MyProjects\text2\aaa.cpp(14) : error C2629: unexpected 'class rectangle ('

D:\VC++6.0\MSDev98\MyProjects\text2\aaa.cpp(14) : error C2238: unexpected token(s) preceding ';'

D:\VC++6.0\MSDev98\MyProjects\text2\aaa.cpp(20) : error C2511: 'rectangle::rectangle' : overloaded member function 'void (double,double,double,double)' not found in 'rectangle'

D:\VC++6.0\MSDev98\MyProjects\text2\aaa.cpp(11) : see declaration of 'rectangle'

D:\VC++6.0\MSDev98\MyProjects\text2\aaa.cpp(25) : fatal error C1004: unexpected end of file found
Error executing cl.exe.

aaa.obj - 4 error(s), 0 warning(s)

回复列表 (共1个回复)

沙发

#include<iostream.h>
class point
{
public:
    point(double i,double j) {x=i,y=j;}
    virtual double area() const{return 0.0;}
private:
    double x,y;
};

class rectangle:public point
{
public:
    rectangle(double,double,double,double);
    virtual double area() const{return w*h;}
private:
    double w,h;
};

rectangle::rectangle(double i,double j,double k,double l):point(i,j)
{
    w=k;h=l;
}
void fun(point &s)
{
    cout<<"area="<<s.area()<<endl;
}
void main()
{
    rectangle rec(3,5,15,25);
    fun(rec);
}

几个语法错误,给你改了

我来回复

您尚未登录,请登录后再回复。点此登录或注册