请解释这个类

来源:百度知道 编辑:UC知道 时间:2024/06/18 10:58:44
class Screen{
public:
Screen& clear(char=bkground);//这是什么意思啊??
private:
static const char bkground='#';
};

Screen& clear(char=bkground);这个函数应该是用指定字符清屏吧!
Screen& 是函数的返回类型,是本身调用这个函数的对象的引用;
char = bkground :是在函数声明时给形参一个默认值bkground及‘#’

返回对象的引用是为了将函数调用连接成单独表达式的形式,例如:
有个对象myclass,我就可以这样调用
myclass.fun1().fun2().fun3();
不需要写成
myclass.fun1();
myclass.fun2();
myclass.fun3();

fun1(),fun2()成员函数的返回类型都要是类类型的引用,如你的问题中的clear函数