简介

RT

参考资料

C++语言的设计与演化

code

一种方式是 定义多个函数对于默认参数的不同提供特定的不同的默认参数

class colored_window : public window {
public:
colored_window(color c=black):window(standard,0,0, 100, 100,c) { }
};

class bordered_window : public window {
public:
bordered_window(border b=single, color bc=blue)
:wlndow(standard,0,0,100,100,black,b,bc) { }
};

另一种技术是提供一些显式操作去修改对默认参数的设置

class w一
args {
wintype wt;
int ulcx, "
ulcy/ xz, yz;
color wc7 be;
border b;
WSTATE ws;
public:
w
—
args() // set defaults
: wt(standard), ulcx(0), iilcy(0), xz(100), yz(100),
wc(black), b(single), be(blue), ws(open) { }
// override defaults:
w_args& ysize(int s) { yz=s;return *this;}
w_args& Color(color c) { wc=:c; return *this; }
w_args& Border(border bb) { b = bb;return *this;}
w_args& Border_color(color c) { bc=c; return *this; }
};

class window {
window(v_args wa);// set options from wa
};
window w;/ / default window
window w( w_args().Color(green).ysize(150) );
posted on 2021-01-24 16:08  HDU李少帅  阅读(129)  评论(0编辑  收藏  举报