Languages-C & C Plus Plus [3i Infotech Placement]: Sample Questions 328 - 328 of 354

Glide to success with Doorsteptutor material for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 328

C & C Plus Plus
Edit

Describe in Detail

Essay▾

What is an action class?

Explanation

  • C ++ function represents an action.
  • However, a delayed action which has to be transmitted before being performed, requires its own data.
  • In this case, it is useful to provide the action as a class.
  • For example manipulators used with iostreams.

As another example consider the simple class containing just one virtual function. class Action {public: virtual int do_it (int) = 0; virtual ~Action () ;}

  • Given this, a member can store actions for later execution without using pointers to functions, without knowing details of objects involved, and without knowing name of the operation. For example: class write_file: public Action {File& f; public: int do_it (int) {return fwrite () . suceed () ;} } ; class error_message: public Action {response_box db (message. cstr () , “Continue” , “Cancel” , “Retry” ) ; switch (db. getresponse () ) {case 0: return 0; case 1: abort () ; case 2: current_operation. redo () ; return 1;} } ;
  • A user of the Action class is completely isolated from any knowledge of derived classes such as write_file and error_message.

Developed by: