靓仔China 2018-08-01 10:50 采纳率: 60%
浏览 981
已采纳

C++改错题,基础不好,希望解释详细点。

#include
using namespace std;
class CMax {
private:
int xx; int yy;
public:
CMax(int x,int y)
{ xx = x;yy = y ; }
void setValue(int x,int y)
{ xx = x;yy = y;}
int max( ){
return xx > yy? xx:yy;
}
};
void main( ){
CMax m( );
m.setValue(20,30);
cout <<″Max=″<<m.max( )<<endl;
}

  • 写回答

5条回答 默认 最新

  • threenewbee 2018-08-01 12:21
    关注

    你这代码中的括号和大把的分号都是中文全角的。
    ();全部需要修改为 ();
    CMax m(); 没有无参数构造函数,在public:里面加上
    CMax() { }
    #include 后面少<iostream>

    在现代的C++编译器上,比如vc++2015,main函数的返回值必须是int才符合标准,而不能是void

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?