I have to construct a class for strings. C++ already has one, but my assignment is a home-made version. I am very lost as to how to make the constructor work. I have toyed with a few things, but I was given a header file to follow and I have no clue what to do. Any help would be appreciated.
class String
{
private:
unsigned Capacity; // Number of memory locations reserved
unsigned Length; // Number of memory locations in use
char * Mem; // Pointer to memory to hold characters
public:
// Construct empty string
//
String()
{
Mem = NULL;
Capacity = 0;
Length = 0;
}
A few specific questions I have:
How are the Mem, Capacity, and Length relavent? After reading the assignment but before looking at the header file I thought i was going to construct a string by taking the sizeof() of the string then applying an array of char[].
I do not see the point of reserving memory for a string when you already know how much space to save...In simpler words I see no point in having a Capacity and a length?
Please help I am in desperate need of help on my c++ classes.