Answer the following statements true (T) or false (F)
1. It is useful to define a class for which no objects may be defined.
2. It is legal to have all member functions of a class be pure virtual functions.
3. A derived class destructor always invokes the base class destructor.
4. The base class destructor must be virtual.
5. This is legal code.
```
class B
{
public:
// . . .
virtual void f() = 0;
};
int main() { B b1, b2; /*. . .*/ }
```
1. True
An abstract class is such a class. These are useful to prevent the implementation of incomplete class definitions and to force the implementation of pure virtual function members in the derived class.
2. True
There is no restriction on having all non-constructor members be pure virtual member functions. You can even have pure virtual destructors.
3. true
A base class destructor always exists, even if it is the compiler supplied destructor. The derived class destructor should just release resources allocated by some constructor. It does not call any other destructor. the run-time system calls the destructors in the order of the inheritance chain.
4. False
There is no requirement that the base class destructor be virtual, but if pointers and allocation are involved, it is wise to do so. It is easy to construct examples where the derived class constructors allocate resources and the corresponding destructors are not called unless the base class destructor is virtual. Many authorities say destructors should always be virtual, but the compiler does not say that.
5. False
This code attempts to define objects of an abstract class. The pure virtual function, virtual void f() = 0; makes the class an abstract base class. Objects may not be defined of abstract base class type.
You might also like to view...
Web apps are becoming increasingly popular. Please define what a Web app is and give an example of one. Also, describe the difference between an ASP and an SaaS, including what these acronyms stand for.
What will be an ideal response?
Select a(n) ________ when you want to display all of the records on the one side of a relationship
Fill in the blank(s) with correct word
When parentheses are used within parentheses, the expressions in the innermost parentheses are always evaluated ____.
A. from left to right B. from right to left C. first D. last
All Dreamweaver websites begin with a local root folder.
Answer the following statement true (T) or false (F)