#include < iostream, h >
class test {
private : int x, y;
public : void test1 ( int a, int b) { x = a ; y = b;}
int max( );
};
int test:max( ) {if(x>y) return x;else return y;}
void main( ){
test a;
a. t

改错题:以下程序中有一处错误,请抄写有错误的语句并给出修改意见。


#include < iostream, h >
class test {
private : int x, y;
public : void test1 ( int a, int b) { x = a ; y = b;}
int max( );
};
int test:max( ) {if(x>y) return x;else return y;}
void main( ){
test a;
a. test1 ( 1,3);
cout << a. max ( ) << endl;
}


【正确答案】:

INT TEST:MAX( ) 成员函数定义时用“::”


【题目解析】:

如果成员函数定义在类体外,则类体内必须要有函数原型,类体外函数定义的前面必须用“类名::”来限定,格式如下:
返回值类型 类名::成员函数名(参数列表)
{
成员函数的函数体
}


Top