| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 522 人关注过本帖
标题:请指教一下下面这个程序的问题,编译的时候是if语句有问题,难道来里面成员函 ...
只看楼主 加入收藏
yljyljylj
Rank: 1
等 级:新手上路
帖 子:13
专家分:7
注 册:2013-8-25
结帖率:50%
收藏
已结贴  问题点数:20 回复次数:7 
请指教一下下面这个程序的问题,编译的时候是if语句有问题,难道来里面成员函数的的结果不能作比较??
#include"iostream"
using namespace std;
class student
{public:
 student(int,int,int);
 int complex();
    int age;
    int height;
    int weight;
    };
student::student(int h,int w,int a)
{height=h;
 weight=w;
 age=a;
}
 int student::complex()
{int z;
 z=(height-weight)/2+age;
 return z;

}
main()
{student stu1(172,60,22),stu2(180,70,25);
cout<<"the compex is "<< ()<<endl;
cout<<"age is  "<<stu1.age<<endl<<"height is  "<<stu1.height<<endl<<"weight is "<<stu1.weight<<endl;
cout<<"the compex is "<< ()<<endl;
cout<<"age is  "<<stu2.age<<endl<<"height is  "<<stu2.height<<endl<<"weight is "<<stu2.weight<<endl;
if( ()>int ())
cout<<"stu1 is more healthy";
else
cout<<"stu2 is more healthy";
return 0;
}
提示的错误是:D:\VC store\practice 03.cpp(28) : error C2440: 'type cast' : cannot convert from 'int (__thiscall student::*)(void)' to 'int'
请指教
搜索更多相关主题的帖子: complex include public return 
2013-09-25 09:10
303770957
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:6
帖 子:838
专家分:2125
注 册:2005-9-10
收藏
得分:20 
分析如下:
#include  <iostream>
using namespace std;
class student
{
public:
    student(int,int,int);
    int complex();
    int age;
    int height;
    int weight;
};
student::student(int h,int w,int a)
{
    height=h;
    weight=w;
    age=a;
}
int student::complex()
{
    int z;
    z=(height-weight)/2+age;
    return z;

}
int main()//既然用 return 0语句了必须有返回值。
{
    student stu1(172,60,22),stu2(180,70,25);
    cout<<"the compex is "<< ()<<endl;
    cout<<"age is  "<<stu1.age<<endl<<"height is  "<<stu1.height<<endl<<"weight is "<<stu1.weight<<endl;
    cout<<"the compex is "<< ()<<endl;
    cout<<"age is  "<<stu2.age<<endl<<"height is  "<<stu2.height<<endl<<"weight is "<<stu2.weight<<endl;
    if( (())>int (()))//这是函数调用结果的比较不是属性或者变量值得比较,要加括号的。
        cout<<"stu1 is more healthy";
    else
        cout<<"stu2 is more healthy";
    return 0;
}

♂ 死后定当长眠,生前何须久睡。♀
2013-09-25 09:24
mcm_mingge
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2013-4-25
收藏
得分:0 
坑爹啊,函数调用要加 ()滴!
2013-09-25 10:52
mcm_mingge
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2013-4-25
收藏
得分:0 
坑爹啊,函数调用要加 ()滴!
2013-09-25 10:58
yljyljylj
Rank: 1
等 级:新手上路
帖 子:13
专家分:7
注 册:2013-8-25
收藏
得分:0 
回复 2楼 303770957
谢谢了,是自己的问题,调用函数结果的时候确实要加括号,因为main函数默认的返回值类型是int,所以就没加,再请假一个问题,在VC里面怎么装MSDN?
2013-09-25 11:46
303770957
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:6
帖 子:838
专家分:2125
注 册:2005-9-10
收藏
得分:0 
问题太多,先结贴在回答下一个问题。

♂ 死后定当长眠,生前何须久睡。♀
2013-09-25 11:49
林兴杰
Rank: 1
等 级:新手上路
帖 子:3
专家分:2
注 册:2013-9-24
收藏
得分:0 
#include<iostream>
using namespace std;
class student
{
public:
    student(int,int,int);
    int age;
    int height;
    int weight;
    int complex();
};
student::student(int h,int w,int a)
{
    height=h;
    weight=w;
    age=a;
}
int student::complex()
{
    int z;
    z=(height-weight)/2+age;
    return z;

}
main()
{
    student stu1(172,60,22),stu2(180,70,25);
    cout<<"the compex is "<< ()<<endl;
    cout<<"age is  "<<stu1.age<<endl<<"height is  "<<stu1.height<<endl<<"weight is "<<stu1.weight<<endl;
    cout<<"the compex is "<< ()<<endl;
    cout<<"age is  "<<stu2.age<<endl<<"height is  "<<stu2.height<<endl<<"weight is "<<stu2.weight<<endl;
    if( (())>(()))
    cout<<"stu1 is more healthy";
    else
    cout<<"stu2 is more healthy";
    system("PAUSE");
    return 0;
}
同学 首先你的书写要规范点  其次我改的这些要注意 ,system("PAUSE")这个不能省略了
2013-09-25 12:23
303770957
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:6
帖 子:838
专家分:2125
注 册:2005-9-10
收藏
得分:0 
可以直接下載VC的msdn進行安裝。好像是2002版的,就是孫鑫的c++視頻中用的那個。

♂ 死后定当长眠,生前何须久睡。♀
2013-09-25 22:49
快速回复:请指教一下下面这个程序的问题,编译的时候是if语句有问题,难道来里面成 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017244 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved