title: Expression: vector subscript out of range C++?
body: <p>I am trying to access a variable, and print it out. However, I encounter the <code>Vector subscript out of range</code> error.</p>
  
  <p>I am doing</p>
  
  <pre><code>cout &lt;&lt; myStruct-&gt;myVector[0].GetCoordinate(0) &lt;&lt; endl;
  </code></pre>
  
  <p>where
  <code>myStruct</code> points to a structure that contains a vector <code>myVector</code> of points. So I am trying to print out its first coordinate.</p>
  
  <hr>
  
  <p><strong>To debug:</strong></p>
  
  <pre><code>cout &lt;&lt; typeid(myStruct-&gt;myVector[0].GetCoordinate(0)).name() &lt;&lt; endl;
  </code></pre>
  
  <p>gives me </p>
  
  <pre><code>float
  </code></pre>
  
  <p>and</p>
  
  <pre><code>cout &lt;&lt; sizeof(myStruct-&gt;myVector[0].GetCoordinate(0)) &lt;&lt; endl;
  </code></pre>
  
  <p>gives me</p>
  
  <pre><code>4
  </code></pre>
  
  <hr>
  
  <p>However, when I directly print its value</p>
  
  <pre><code>cout &lt;&lt; myStruct-&gt;myVector[0].GetCoordinate(0) &lt;&lt; endl;
  </code></pre>
  
  <p><strong>Error message:</strong></p>
  
  <p><img src="https://i.stack.imgur.com/8l16L.png" alt="enter image description here"></p>