How to initialize a vector in a struct in c++
<p>I am having a problem with vectors in c++. I am new to c++ so keep this in mind please.</p>

<p>So I have the following struct in the begining of my program:</p>

<pre><code>typedef struct grupo
{
    float transX, transY, transZ, rotX, rotY, rotZ, rotAngle, scaleX, scaleY, scaleZ;
    char **modelos;
    struct grupo** grupos;
    int nNomes = 0, nGrupos=0;
    std::vector&lt;float&gt; vertices;
};

struct grupo *grupo;
</code></pre>

<p>And I just start the main like this:</p>

<pre><code>grupo = (struct grupo*)malloc(sizeof(struct grupo));
grupo-&gt;modelos = (char **)malloc(sizeof(1));
grupo-&gt;grupos = (struct grupo **)malloc(sizeof(struct grupo));
</code></pre>

<p>And in the middle of main I am tryting to use this:</p>

<pre><code>grupo-&gt;vertices.push_back(x);
</code></pre>

<p>But it keeps crashing the program. I am using visual studio, and using debugging mode. I can see that is when pushing X to the vector that crashes (x has a value). I've tried to change the vector to an array of floats. So the problem i can imagine is with the initialization of the vector... Can you help with what am I missing?</p>

<p>Thank you :)</p>