[Cpp]
# 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 <endl;
}
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 );
}
Author: peng654321