Why aren't objects being pushed to this vector (when it's a member of a struct)?
<p>I have the following code, which loops through an array of <code>menuoptions</code> and on each iteration,  creates a <code>ScaledRect</code> object and pushes it to a vector. This vector is a member of a struct.</p>

<p>I have verified that the ScaledRect is created with the correct values, yet when I print back the contents of the <code>regions</code> vector ( in the second loop ), the loop never terminates and the values are garbage. </p>

<pre><code>class ScaledRect : public Rect
{
public:
    ScaledRect(int x1, int y1, int x2, int y2);
};
ScaledRect::ScaledRect(int x1, int y1, int x2, int y2):
    _x1(x1), _y1(y1), _x2(x2), _y2(y2){}

// ScaledRect doesn't have copy constructor, but Rect does
Rect::Rect( const Rect &amp;rect)
{
x1=rect.x1; y1=rect.y1; x2=rect.x2; y2=rect.y2; bClean=KD_FALSE;
}

typedef struct
{
    std::vector&lt;ScaledRect&gt; regions;
}interface;

void PushRegions( interface * myself )
{
    int i = 0;
    while(menuoptions[i].callback != -1 )
    {
        ScaledRect s = 
          ScaledRect(menuoptions[i].x1, 
                     menuoptions[i].y1,
                     menuoptions[i].x2, 
                     menuoptions[i].y2);            
        myself-&gt;regions.push_back( s );
        i++;
    }

    std::vector&lt;ScaledRect&gt;::iterator iter = myself-&gt;regions.begin();
    std::vector&lt;ScaledRect&gt;::iterator done = myself-&gt;regions.end();

    while(iter != done)
    {
        iter-&gt;Dump();
        iter++;
    }
}
</code></pre>

<p>EDIT
Please note - I've just edited - the memory for <code>theinterface</code> is created and I do actually pass in the address of <code>theinterface</code> to this function. (However, I have simplified those two lines here - what actually happens is that <code>PushRegions</code> gets called via a ptr to a function, on a piece of newly allocated memory the size of an <code>interface</code> ).</p>

<p>I can't post all of the code here - but minimally its:</p>

<pre><code>Func pfunc = GetPFuncForInterfaceObj();
size_t  numbytes = GetSizeForInterfaceObj();
char memory = new char[numbytes];
pfunc(memory);
</code></pre>

<p><code>pfunc</code> ends up being <code>PushRegions</code> and <code>memory</code> ends up being passed as an <code>interface</code>.</p>

<p>When I push the <code>ScaledRect</code> object to a <code>vector</code> declared at the top of <code>PushRegions()</code> it works. Has anyone got any ideas why?</p>
