title: dynamic string array constructor and null returns
body: <pre><code>class DSArray {
  
  private:
      int size;
      string *dynamicArray;
  
  public:
      DSArray();
      DSArray(int size, string []);
      ~DSArray();
      int getSize() const;
      void addEntry(string newString);
      bool deleteEntry(string find);
      string getEntry(const int index) const;
      void operator = (const DSArray&amp; obj);
      string operator [] (int index);
      friend ostream&amp; operator &lt;&lt; (ostream &amp;out, const DSArray&amp; array);
  
  
  };
  
  DSArray::DSArray(){
      size = 0;
      dynamicArray = NULL;
  }
  
  DSArray::DSArray(int size, string []){
      dynamicArray = new string[size];
      for (int i = 0; i &lt; size; i++){
          dynamicArray[i] = getEntry(i);
      }
      size = getSize();
  }
  
  DSArray::~DSArray(){
      delete[] dynamicArray;
  }
  
  int DSArray::getSize() const{
      return size;
  }
  
  
  void DSArray::addEntry(string newString){
      string *tempPtr = dynamicArray;
      dynamicArray = new string[size + 1];
      dynamicArray[size].assign(newString);
      for(int i = 0; i &lt; size; i++){
          dynamicArray[i] = tempPtr[i];
      }
      if(size &gt; 0){
          delete[] tempPtr;
      }
      size++;
  }
  
  ostream&amp; operator &lt;&lt; (ostream &amp;out, const DSArray&amp; array){
      for (int i = 0; i &lt; array.getSize(); i++)
          out &lt;&lt; array.dynamicArray[i];
      return out;
  }
  
  
  
  bool DSArray::deleteEntry(string toDelete)
  {
      int index;
      for(index = 0; index &lt; size; index++)
      {
          if(dynamicArray[index] == toDelete) break;
      }
  
      if(index == size) return false;
  
      string *newArray = new string[size--];
  
      int i;
      for(i = 0; i &lt; index; i++) newArray[i] = dynamicArray[i];
      for(int k = index + 1; k &lt;= size; k++, i++) newArray[i] = dynamicArray[k];
  
      delete [] dynamicArray;
      dynamicArray = newArray;
  
      return true;
  }
  
  string DSArray::getEntry(const int index) const{
      static string emptyStr = "";
      if(index &gt; size){
          return emptyStr;
      }
      else{
          return dynamicArray[index];
      }
  
  }
  
  
  void DSArray::operator = (const DSArray&amp; obj){
      DSArray temp(obj);
      if(this-&gt;size != 0)
          delete[] this-&gt;dynamicArray;
      this-&gt;size = obj.getSize();
      this-&gt;dynamicArray = new string [this-&gt;size];
      for(int i = 0; i &lt; this-&gt;size; i++)
          this-&gt;dynamicArray[i] = obj.getEntry(i);
  }
  
  string DSArray::operator [] (int index){
      string emptyString = "";
      if (index &gt;= size){
          return emptyString;
      }
      return dynamicArray[index];
  }
  
  int main()
  
  {
      DSArray foods;
      string x[] = {"Burrito", "Sushi", "Pizza"};
      DSArray A(3, x);
      cout &lt;&lt; A;
      A[3] = "Spaghetti";
      foods.addEntry("Steak");
      foods.deleteEntry("Sushi");
  
  
  
  
      return 0;
  
  }
  </code></pre>
  
  <p>I'm trying to test my functions in main but it's not actually displaying anything in the console. I was told that my constructor isn't setting the size correctly because calling getSize returns the object's size which hasn't been initialized yet. How exactly do i fix this? Also does anyone know if the getEntry function get return a null instead of an empty string? My assignment says it should return a null, however, when i do return a null it gives me a runtime error. Any help is appreciated. Thanks!</p>