Share
Explore BrainMass

C++ Programming: Constructors and Destructors

Please help identify the following statements as either true or false. If an answer is true, I need to explain why and, where appropriate, provide an example. If the answer is false, I also need to explain why.
a. Constructors can have names different from their classes.
b. Destructors have default arguments.
c. If a program uses the delete operator, a destructor is not needed.
d. Explicit constructors need to be included in every class.
e. Destructors are called each time an object goes out of existence.
f. A class can have several default constructor functions.
g. Constructors need to be declared for each class.
h. Constructors are automatically called when objects are created.

Solution Preview

a. Constructors can have names different from their classes - FALSE.
Constructor must always have the same name as their class, otherwise the compiler will not know that it is a constructor. The declaration syntax is different from other members - there is no return type defined.
Eg.

class MyClass
{
public:

MyClass();
};

b. Destructors have default arguments. - FALSE
Destructors have no arguments.
Eg.

class ...

Solution Summary

The solution discusses c++ programming including constructors and destructors.

$2.19