Answers to Self-Review Exercises

  1. 9.1

    1. dot (.), arrow (->).

    2. private.

    3. public.

    4. Default memberwise assignment (performed by the assignment operator).

    5. friend.

    6. initialized.

    7. static.

    8. this.

    9. const.

    10. default constructor.

    11. non-static.

    12. before.

    13. :: scope resolution operator.

  2. 9.2

    1. Error: Destructors are not allowed to return values (or even specify a return type) or take arguments.

      Correction: Remove the return type void and the parameter int from the declaration.

    2. Error: Constructors are not allowed to return values.

      Correction: Remove the return type int from the declaration.

    3. Error: The class definition for Example has two errors. The first occurs in function getIncrementedData. The function is declared const, but it modifies the object.

      Correction: To correct the first error, remove the const keyword from the definition of getIncrementedData. [Note: It would also be appropriate to rename this member function, as get functions are typically const member functions.]

      Error: The second error occurs in function getCount. This function is declared static, so it’s not allowed to access any non-static class member (i.e., data).

      Correction: To correct the second error, remove the output line from the getCount definition.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset