Retrieve object instance from map
<p>I'm new to C++ and I'm trying to make a little game. I have this class named "UnitController" which stores multiple instances of the class "Unit" in a map. The class also has a method "getUnit" which should return one of the stored units.</p>

<p>It seems this method is only partially working. I think I get a copy of the unit instead of the requested instance.</p>

<p>Could anyone point me int the right direction?</p>

<pre><code>#include "UnitController.h"
#include "Unit.h"

using namespace ci;
using std::map;

UnitController::UnitController()
{
}

void UnitController::addUnit( Vec2f position )
{
    Unit mUnit = Unit();
    mUnit.setup( position );
    Units.insert( std::pair&lt;int,Unit&gt;( Units.size()+1, mUnit ) );
}

Unit UnitController::getUnit( int k )
{
    Unit selectedUnit = Units[0];
    return selectedUnit;
}

void UnitController::update()
{
    for( map&lt;int,Unit&gt;::iterator u = Units.begin(); u != Units.end(); ++u ){
        u-&gt;second.update();
    }
}

void UnitController::draw()
{
    for( map&lt;int,Unit&gt;::iterator u = Units.begin(); u != Units.end(); ++u ){
        u-&gt;second.draw();
    }
}
</code></pre>
