title: C++ Allocation of array of struct
body: <p>I have to allocate in C++ an array of struct, any struct contains two vector of int. This is my struct: </p>
  
  <pre><code>typedef struct _Sample{
  vector&lt;int&gt; contourX;
  vector&lt;int&gt; contourY;
  }Sample;
  </code></pre>
  
  <p>To allocate this array I write the following code:</p>
  
  <pre><code>data = (struct _Sample*) malloc(sizeof(struct _Sample) * nsamples);
  </code></pre>
  
  <p>When I try to assign a Sample element to data[0] I have an error a runtime. Where is the problem?</p>