Setting and accessing member variables in C++
<p>I'm writing an open source project for the Xbox 360, it's my first time using C++ and I'm obviously doing something (Most likely many things) wrong.</p>

<p>My specific problem at the moment is that I create many instances of a class, passing in a reference to an object in the constructor, and setting a member variable to that object.</p>

<p>Later, when I access these objects, the member variable does not contain the object I assigned to it in the constructor.</p>

<p>Also, these objects have an Update(float x, float y) method, in this method I simply assign the x and y to member variables _x and _y.</p>

<p>When I access these values later, they are garbage.</p>

<p>I'm going to try post the relevant code here, but there may be something I miss, so just in case here is a link to the github project <a href="https://github.com/Diggs/Xenu/" rel="nofollow">Github - Xenu</a>.</p>

<p>The class I'm referring to is source/GUIApplicationPanel and the instantiating/using of them is in source/GUIManager.</p>

<p>Here is the object I am instantiating many instances of:</p>

<pre><code>GUIApplicationPanel.H

class GUIApplicationPanel {
public:
    GUIApplicationPanel(LibXenonApplication libXenonApplication);
    void update(float x, float y);
    void draw();

private:
    LibXenonApplication application;
    float _x, _y;
};

GUIApplicationPanel.CPP

GUIApplicationPanel::GUIApplicationPanel(LibXenonApplication libXenonApplication) 
{
    application = libXenonApplication;
}

void GUIApplicationPanel::update(float x, float y)
{
    _x = x;
    _y = y;
}

void GUIApplicationPanel::draw()
{
    Draw::DrawColoredRect(_x, _y, 0.3f, 0.3f, ThemeManager::GetPanelColor());
}
</code></pre>

<p>And here is the code that creates them:</p>

<pre><code>GUIManager.H

class GUIManager {
public:
    void update(controller_data_s controller);

    void draw();

private:
    /* SNIP SNIP */

    vector&lt;GUIApplicationPanel&gt; *currentPanels;

    vector&lt;GUIApplicationPanel&gt; applicationPanels;
};

GUIManager.C

vector&lt;LibXenonApplication&gt; applications = LibXenonApplicationManager::GetApplications(applicationsPath);

// Create panels for applications
for(vector&lt;LibXenonApplication&gt;::iterator iter = applications.begin(); iter != applications.end(); ++iter) {
     applicationPanels.push_back(GUIApplicationPanel(*iter));
}
</code></pre>

<p>Here is the code that updates them:</p>

<pre><code>currentPanels = &amp;applicationPanels;

// Render each screens worth of panels
    for(int currentPass = 0; currentPass &lt; renderPasses; currentPass++) {

        horizontalOffset = currentPass * 1.0f;

        for(int verticalPanel = 0; verticalPanel &lt; verticalPanels; verticalPanel++) {

            for(int horizontalPanel = 0; horizontalPanel &lt; horizontalPanels; horizontalPanel++) {

                // Make sure we haven't exceeded the amount of panels we're drawing...
                if(panelIndex &gt;= currentPanels-&gt;size()){break;}

                // Get the panel at the current index
                GUIApplicationPanel currentPanel = currentPanels-&gt;at(panelIndex);

                // Calculate its position
                float panelX = horizontalOffset + xStart + (horizontalPanel * panelWidth) + (horizontalPanel * panelGap);
                float panelY = yStart + (verticalPanel * panelHeight) + (verticalPanel * panelGap);

                // Update the panel
                currentPanel.update(panelX, panelY);

                // Move to the next panel...
                panelIndex++;
            }
        }
    }
</code></pre>

<p>And lastly here is the code that accesses values on them:</p>

<pre><code>for(vector&lt;GUIApplicationPanel&gt;::iterator iter = currentPanels-&gt;begin(); iter != currentPanels-&gt;end(); ++iter) {
    iter-&gt;draw();
}
</code></pre>

<p>To be honest I'm all out of ideas - Acessing the application variable on a panel anywhere other than the constructor results in it being garbage, and likewise with _x and _y (Other than in the update method).</p>

<p>I put some logging in, so a line will be logged in the update method of the panel logging the values of _x and _y after they've been set, as well as showing the name of the application (Which comes out blank in the log).</p>

<p>A line will also be logged when the draw method is called showing the current values of _x, _y and application:</p>

<pre><code>Updating  to x -0.70 y 0.40
Updating  to x -0.30 y 0.40
Updating  to x 0.10 y 0.40
Updating  to x 0.50 y 0.40
Updating  to x 0.90 y 0.40
Updating  to x -0.70 y 0.80
Updating  to x -0.30 y 0.80
Updating  to x 0.10 y 0.80
Updating  to x 0.50 y 0.80
Drawing  at x 0.00 y 0.00
Drawing  at x 0.00 y 0.00
Drawing  at x 0.00 y 0.00
Drawing  at x 0.00 y 0.00
Drawing  at x 0.00 y 0.00
Drawing  at x 0.00 y 0.00
Drawing  at x 0.00 y 0.00
Drawing  at x 0.00 y 275577729171396449271808.00
Drawing  at x 0.00 y 0.00
</code></pre>
