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;
}

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

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

以下代码是修改好的,已经编译确认,你直接复制粘贴过去就能运行,抄的话,估计你还得抄错。

 #include <iostream>
using namespace std;
class CMax {
private:
int xx; int yy;
public:
CMax() { }
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;
}
};
int main() {
CMax m;
m.setValue(20,30);
cout <<"Max="<<m.max()<<endl;
}

CMax缺少构造析构函数

中文括号,分号肯定不行

#include后面缺少iostream,void改成int,后面补上return 0;