璁捐妯″紡锛歴tate妯″紡
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了璁捐妯″紡锛歴tate妯″紡相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/cpp' title='cpp'>cpp state oid return pre 鎺ュ彛 澶嶆潅 div
鏍稿績锛?鎶婄姸鎬佺殑鍒ゆ柇閫昏緫杞Щ鍒拌〃绀轰笉鍚岀姸鎬佺殑涓€绯诲垪绫诲綋涓紝鍙互鎶婂鏉傜殑鍒ゆ柇閫昏緫绠€鍖?/p>
渚嬪瓙锛?/p>
class State //鐘舵€佹帴鍙? public: virtual void show() = 0; ; class NormalState: public State //姝e父鐘舵€? public: virtual void show() cout << "Normal state, communicate success." << endl; ; class CritcalState: public State //绱ф€ョ姸鎬? public: virtual void show() cout << "Critcal state, communicate failed." << endl; ;
class Communicate public: void criticalState() //绱ф€ョ姸鎬佷笅瀵瑰簲鐨勬搷浣? CritcalState().show(); void normalState() //姝e父鐘舵€佷笅瀵瑰簲鐨勬搷浣? NormalState().show(); ;
int main() Communicate c; c.criticalState(); c.normalState(); return 0;
以上是关于璁捐妯″紡锛歴tate妯″紡的主要内容,如果未能解决你的问题,请参考以下文章