Command mode C ++ code

Source: Internet
Author: User
# Include <iostream> # include <string> # include <vector> using namespace STD; Class commandbase {public: Virtual void run () = 0; private :}; class command1: public commandbase {public: command1 (string strname): m_strname (strname) {}; void run () {cout <m_strname <Endl;} PRIVATE: String m_strname ;}; class command2: Public commandbase {public: command2 (string strname): m_strname (strname) {}; void run () {cout <m_strname <End L;} PRIVATE: String m_strname;}; Class command3: Public commandbase {public: command3 (string strname): m_strname (strname) {}; void run () {cout <m_strname <Endl;} PRIVATE: String m_strname;}; Class exclude {public: void add (commandbase & command) {m_vetorcommand.push_back (& command );} void run () {vector <commandbase *>: iterator itr = m_vetorcommand.begin (); While (itr! = M_vetorcommand.end () {(* itr ++)-> Run () ;}} PRIVATE: vector <commandbase *> m_vetorcommand; static exclude m_cexclude ;}; int main () {command1 ccommand1 ("cmd1"); command2 ccommand2 ("cmd2"); command3 ccommand3 ("cmd3"); Exclude cexclude; cexclude. add (ccommand1); cexclude. add (ccommand2); cexclude. add (ccommand3); cexclude. run (); While (1 );}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.