why does my destructor code execute on instantiation and what is it really doing?
<p>If I place breakpoints in my destructor I notice that all the code is run through when I instantiate said object, but the lines don't have any effect (as in, the delete does not actually seem to delete the object) What is really going on here?</p>

<p>I am using visual studio, is this an artifact (is that the right word?) of the program?</p>

<p>destructor being called:</p>

<pre><code>Brain::~Brain()
{
    for (unsigned int i = 0; i &lt; weapons.size(); i++)
    {
         delete weapons[i];
    }
}
</code></pre>

<p>if I place breakpoints in here, they get triggered when the Brain is instantiated! and again when I close the program.</p>

<p>here is the objects constructor:</p>

<pre><code>Brain::Brain(
int health,
Level&amp; level,
vector&lt;Agent&gt;&amp; agents,
//vector&lt;Pickup&gt;&amp; pickups,
D3DXCOLOR colour,
Mesh&amp; mesh)
: Entity(colour, mesh), gunOffset(D3DXVECTOR3(0, 0, 1.0f)), 

level(level),
agents(agents),
//pickups(pickups),
colour(colour),
health(health),

enemies(vector&lt;int&gt;()),
seenEnemies(vector&lt;int&gt;()),
seenPickups(vector&lt;int&gt;()),

seenEnemyMarkers(vector&lt;BoundingSphere&gt;()),
seenPickupMarkers(vector&lt;BoundingSphere&gt;()),
weapons(vector&lt;Gun*&gt;()),
RoomKills(vector&lt;int&gt;()),
pathVisualisation(vector&lt;Edge&gt;()),
search(vector&lt;int&gt;()),

WALKING_INCREMENT(0.06f),
TOLERANCE(0.1f),
COMBAT_SEARCH_TIME(0),
SHOTGUN_STOPPING_DISTANCE(1.5f), PISTOL_STOPPING_DISTANCE(5.0f),
SPAWNTIME(120),
IMPACT_DISTANCE(0.6f),
FIELD_OF_VIEW(0.95f),
MARKER_SIZE(0.5f)
{
currentNodeInSearchPathInt = 0;
combatSearchCycle = 0;
spawnCycle = 0;
globalNodePositionIndex = 0;
//fightOrFlight = 0;

 chosenTarget = -1;
 previousTarget = -1;
 pickupMemory = -1;
 agentMemory = -1;



for (unsigned int i = 0; i &lt; level.RoomCentreNodeVectors().size(); i++)
{
    RoomKills.push_back(level.Nodes()[level.RoomCentreNodeVectors()[i][0]].Room());
}

weapons.push_back(new Pistol());
weapons.push_back(new Rifle());
weapons.push_back(new Shotgun());

prevTargetType = AGENT;
targetType = AGENT;
currentWeapon = PISTOL;

state = SPAWN;
}
</code></pre>

<p>could it have something to do with this?</p>

<pre><code>for (int i = 0; i &lt; 2; i++)
{
agents.push_back(Agent(100, *level, agents/*, level-&gt;Pickups()*/, D3DXCOLOR(1.0F, 0.4f, 0.4f, 1.0f), *mesh));
}
</code></pre>

<p>Agent inherits from Brain.</p>

<p>This is Agent:</p>

<pre><code>#ifndef AGENT_H
#define AGENT_H

#include &lt;d3d10.h&gt;
#include &lt;d3dx10.h&gt;
#include "Brain.h"

class level;

class Agent : public Brain
{
private:
    int counter;
    Level&amp; level;

int previousState;

const int
    TARGET_IS_AGENT,
    TARGET_IS_OBJECT,
    TARGET_IS_AGENT_MEMORY,
    NO_TARGET;

int fightFlightThreshold;

const int SHOTGUN_DISTANCE_TOLERANCE;
public:
Agent(int health,
    Level&amp; level,
    vector&lt;Agent&gt;&amp; agents,
    D3DXCOLOR colour,
    Mesh&amp; mesh);
void UpdateAgent();
void DrawAgent(D3DXMATRIX matView, D3DXMATRIX matProjection, bool dataVis);
void RegenerativeHealth();
//int TargetChooser();
};

#endif
</code></pre>
