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

C++菜鸟问题

sdoaa12343 发布于 2010-07-15 12:33, 1145 次点击
#include <iostream>
using namespace std;
class Human
{
public :
    void GetStature(){cout<<stature;}
    void GetWeight(int x){stature=x;}
    void get_weight();
    void setweight(int x);
private:
    int stature;
    int geight;
};
Human::get_weight()
{
    cout<<geight;
}
void setweight(int x)
{
    geight=x;
}
void main()
{
    Human Mike;
    int y;
    cin>>y;
    Mike.GetWeight(y);
    Mike.GetStature();
    cout<<endl;
    Mike.setweight(80);
    cout<<"Mike的体重是:"
    Mike.get_weight();


}



//请问哪里错了?
11 回复
#2
sdoaa123432010-07-15 12:38
Human::get_weight()
{
    cout<<geight;
}
void setweight(int x)


这里错了,应该是
void Human::get_weight()
{
    cout<<geight;
}
void Human::setweight(int x)






但是修改之后还是有一个地方错了,提示

最后那段错了,
 Mike.get_weight();
这段..
#3
flyingcloude2010-07-15 12:40
全都是小错误,找找就好了。
#4
flyingcloude2010-07-15 12:41
回复 2楼 sdoaa12343
少了分号
#5
sdoaa123432010-07-15 12:41
问题已解决,原来是
倒数第2行的
cout<<"Mike的体重是:"

后面没有;
#6
sdoaa123432010-07-15 12:42
回复 4楼 flyingcloude


- -!
写代码一点不细心都会死人
#7
南国利剑2010-07-15 13:09
呵呵,路过。
#8
取而代之2010-07-15 22:46
#include <iostream>
using namespace std;
class Human
{
public :
    void GetStature(){cout<<stature;}
    void GetWeight(int x){stature=x;}
    void get_weight();
    void setweight(int x);
private:
    int stature;
    int geight;
};
void Human::get_weight()
{
    cout<<geight;
}
void Human::setweight(int x)
{
    geight=x;
}
void main()
{
    Human Mike;
    int y;
    cin>>y;
    Mike.GetWeight(y);
    Mike.GetStature();
    cout<<endl;
    Mike.setweight(80);
    cout<<"Mike的体重是:";
    Mike.get_weight();
}

三个小错误。细心一点。
#9
ToBeOOP2010-07-16 13:12
有时候写一百多行代码下来如果不细心点就得有十多处错误的,得细心细心再细心!
#10
qianzezi_pku2010-07-22 22:31
改好之后,楼主对照一下:

#include <iostream>
using namespace std;
class Human
{
public:
    void GetStature( )   {cout<<stature;}
    void SetStature(int x){stature=x;}
    void GetWeight( );
    void SetWeight(int x);
private:
    int stature;
    int geight;
};

void Human::GetWeight()
{
    cout<<geight;
}
void Human::SetWeight(int x)
{
    geight=x;
}
void main()
{
    Human Mike;
    int   y;
    cin>>y;
    Mike.SetStature(y);
    Mike.GetStature();
    cout<<endl;
    Mike.SetWeight(80);
    cout<<"Mike的体重是:";
        Mike.GetWeight();   
}
#11
pangding2010-07-23 00:26
以下是引用ToBeOOP在2010-7-16 13:12:54的发言:

有时候写一百多行代码下来如果不细心点就得有十多处错误的,得细心细心再细心!

犯点错误是很正常的事,得学会看错误提示。语法错误是最简单的错误,即使一编译冒了几十个出来,一般几分钟也能搞定,不用太担心。而且编程久了,看的和写的代码多了,有好多错误就自然不犯了。
#12
魔_ZeroDJ2010-07-23 16:59
都很积极啊。。
1