Answers/Solutions to Exercises in Chapter 8, Exercise 1

E1: Consider the following C++ class:

class A {
    public:
        int a;
        char b;
        A() { a = 0; b = '\0'; }
};//end class A

Is it a problem that the class does not have a destructor? Is it a problem that the class does not have a copy constructor? Is it a problem that the class does not have an assignment?

A1: The class does not need any explicit destructor, as there is no dynamic memory allocation involved, and thus the memberwise destruction is sufficient. The same goes for the copy constructor, the memberwise copying is fine, ditto for assignment.

Back to Answers/Solutions Index                          Back to Answers/Solutions for Chapter 8 Index