Topic: Destructors mandatory?


Author: asayyad@acs.ryerson.ca (Afzal Sayyad - CNED/F93)
Date: 21 Aug 1994 21:01:56 GMT
Raw View
I'm writing a recursive program which seems to soak up tons of memory!  One
thing I haven't employed are destructors because none of my classes
contain pointers.  My question is - even if you use composition of other
classes, but don't have any pointer data members, is there any need to
specify destructors?  Can the compiler use a default destructor.  The
following case demonstrates what I mean:

class A {
 int number;
 A(int &);
};
....
class B {
 int number2;
 A aClass;
 B(int &, A &);
}

The idea is that destructors are not needed because the default
destructor in class B destroys data member aClass by calling the
destructor (which is also default) for class A, which destroys the
predefined integer data member.  This is the rationality I'm following -
but please let me know if I'm doing something wrong here or missing some
critical point.  Thanks all.

Afzal Sayyad