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

unexpected end of file found

一切皆安 发布于 2011-06-04 12:02, 440 次点击
#include<iostream>
using namespace std;
class father
{
private:
        int fatherheight,fatherweight;
public:
    void setfatherheight(int fatherheight){fatherheight=fatherheight;
    void setfatherweight(int fatherweight){fatherweight=fatherweight;
    void Showfatherheight()
    {
    cout<<"height="<<fatherheight<<"\t"<<"weight="<<fatherweight<<endl;
    }
};
class son: public
{
private:
    int sonwidth,sonlength;
public :
    void setwidth(int sonwidth){sonwidth=sonwidth;}
    void setlength(int sonlength){sonlength=sonlength;}
    void Showsondate(){cout<<"length="<<sonlength<<"\t"<<"width="<<sonwidth<<endl;
};
int main()
{
son a;                       
a.setfatherheight(160);
a.setfatherweight(60);
a.setsonwidth(60);
a.setsonlength(80);
a.Showfatherheightweight();
a.Showdatesondate();
return 0;
}
好像没错误吧,不知道错在哪,郁闷
5 回复
#2
caihongf2011-06-04 12:27
不明白,应该好好学习请教一下
#3
ToBeStronger2011-06-04 13:54
回复 楼主 一切皆安
class son: public
楼主这一行怎么回事,后面至少应该跟上 public father吧
#4
ToBeStronger2011-06-04 14:01
回复 楼主 一切皆安
a.setsonwidth(60);
a.setsonlength(80);
a.Showfatherheightweight();
a.Showdatesondate();
return 0;
还有这几行,楼主明显调用的方法名写错了,应该是a.setwidth(60),a.setlength(80);楼主你好好看看你是son类里面方法是怎么写的
#5
ToBeStronger2011-06-04 14:18
回复 楼主 一切皆安
#include<iostream>
using namespace std;
class father
{
private:
    int fatherheight,fatherweight;
public:
    void setfatherheight(int height){fatherheight=height;}
    void setfatherweight(int weight){fatherweight=weight;}
    void Showfatherheightweight()
    {
        cout<<"height="<<fatherheight<<"\t"<<"weight="<<fatherweight<<endl;
    }
};
class son: public father
{
private:
    int sonwidth,sonlength;
public :
    void setsonwidth(int width){sonwidth=width;}
    void setsonlength(int length){sonlength=length;}
    void Showsondate(){cout<<"length="<<sonlength<<"\t"<<"width="<<sonwidth<<endl;};
};
int main()
{
    son a;                       
    a.setfatherheight(160);
    a.setfatherweight(60);
    a.setsonwidth(60);
    a.setsonlength(80);
    a.Showfatherheightweight();
    a.Showsondate();
    return 0;
}
我帮你修改过的,已经运行成功,你对照对照吧

#6
一切皆安2011-06-04 15:47
谢谢了
1