title: How to dereference an array element (C++)
body: <p>I wanted to create an array of a specific size using a variable, but allegedly the only way to do that is to use pointers.</p>
  
  <pre><code>int size = 5;
  string* myArray = new string[size];
  </code></pre>
  
  <p>I now want to assign an element from this array to another variable, which I believe will only work through dereferencing. The following line of code doesn't work. How do I fix it?</p>
  
  <pre><code>string line;
  
  myArray[0] = "Hello";
  line = *myArray[0];
  </code></pre>
  
  <p>Edit:</p>
  
  <p>I just want to clarify something: Using the normal "myArray[0]" code doesn't work either. It compiles, but causes a crash. Here's some more specific code regarding what I want to do.</p>
  
  <pre><code>void MyClass::setLine(string line)
  {
      myLine = line; /*This is a private variable in MyClass*/
  }
  
  ///////////////
  
  MyClass* elements = new MyClass[size];
  
  elements[0].setLine(myArray[0]);
  </code></pre>
  
  <p>I want to assign the array element to a private variable from a class, but the program crashes when I try to assign the value to the private variable.</p>