I am trying to do this project. The basic directions are to make a program with a class that has two private variables, one a dynamic array of strings and the other is a variable that determines the length of the array. I am supposed to have a member function to add entries and another to delete entries. I have gotten the code to compile and am debugging it. This is the debug version of the main:
1. Your default constructor creates an array of length 1. Why? Why not 0?
2. Your copy constructor calls get_name(i), which calls get_name on *this, not on
the object from which you are copying.
3. Why do addEntry and deleteEntry take namearrays as parameters and return a namearray?
You want to add or remove from *this, so there is no need for the extra parameter.
4. There are other problems with addEntry and deleteEntry, but I won't go into them until you
fix #3.
5. Your assignment operator leaks memory. In the expression a = b; where a and b are
namearrays, a may already contain names prior to the assignment. You need to ensure
that you free the memory used by a's internal array prior to "overwriting" it.
6. set_size() is a pointless method particularly in a public interface, unless you actually go and
create those elements. Think about what would happen if the array contained 5 elements,
then the user called set_size( 10 ). Where are indices 5-9 stored? You haven't even allocated
memory for them.