#25 Fix constructors.


Patch: fix-constructors-8a.patch

This patch fixes bugs in various constructors. It also
defines an
explicit constructor and an explicit virtual destructor
for every

This text looks prettier if you read it under Emacs
with M-x outline-mode.

*All of the constructors and destructors are now
defined in the
appropriate <class>.cpp file, instead of being inline
in the <class>.h
file. This reduces the size of the executable;
otherwise they get
redundantly instantiated in every source file they're
used in.

*All classes now have virtual destructors. This is
needed so that
destructors on polymorphic subclassed objects will work
even when they're being referred to by a pointer to
objects of an
ancestral type.

*Bugs fixed in various constructors:
**class Althea: Needed a constructor to zero-initialize
some members.
This never showed up because the only instances of
objects of the
Althea class are both global variables, and with
globals, their memory
starts off automatically zeroed at program load time.
The result of *that* is that if someone ever *were* to
instantiate an object
of class Althea on the stack or via the memory manager,
the bug would
only appear then.

*Some classes had constructors that would have worked
in Java,
but sneakily fail in C++. I fixed them.

For example, the no-arg constructor:
Folder::Folder() {
Folder("New Folder");

did not initialize the new folder object's folder name.
Instead, it
invoked the constructor Folder(string), which then in
turn instantiated a
new Folder with its title set to "New Folder", and then
destroyed that new Folder!

The classes Server and Folder had this bug.

*Old Folder constructor did not initialize server_ptr.
Lurking bug. Fixed.

*strings are initialized to "" by default
so no need to do it again in a constructor. I've
excised such
initializations from the constructor code.

*Redundant code consolidated.
Some classes (such as Folder or Server) with more than
one constructor
now have each constructor call a single central
initialize() function.
This removed code duplication.

*All classes now have constructors and destructors.
Some of these are empty in the patches I'm submitting
here. They are important in my own work, though. In
*my* working tree, they
initialize some #ifndef NDEBUG internal consistency
checks (assertions
and the like) that I've already used in my own Althea
sources to
catch bad-pointer bugs quickly.

I do not plan to send patches for those consistency
checks unless one
of the core developers actually cares about it and
understands why
this is a good thing to have. The idea is well
discussed in Kernighan
and Pike's ``The Practice of Programming'' and in Steve
``Writing Solid Code''


  • Steven Augart

    Steven Augart - 2002-02-16
    • priority: 5 --> 7

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks