如果我在我的析構函數中放置斷點,我注意到當我實例化所述對象時,所有代碼都會運行,但行沒有任何影響(如在刪除實際上似乎並沒有刪除該對象)什麼是真的要在這裏?爲什麼我的析構函數代碼在實例化上執行,它在做什麼?
我正在使用visual studio,這是一個程序的神器(這是正確的詞?)?
析構函數被調用:
Brain::~Brain()
{
for (unsigned int i = 0; i < weapons.size(); i++)
{
delete weapons[i];
}
}
如果我把斷點在這裏,他們的時候,大腦被實例化被觸發!當我關閉程序的時候。
這裏是對象的構造函數:
Brain::Brain(
int health,
Level& level,
vector<Agent>& agents,
//vector<Pickup>& pickups,
D3DXCOLOR colour,
Mesh& mesh)
: Entity(colour, mesh), gunOffset(D3DXVECTOR3(0, 0, 1.0f)),
level(level),
agents(agents),
//pickups(pickups),
colour(colour),
health(health),
enemies(vector<int>()),
seenEnemies(vector<int>()),
seenPickups(vector<int>()),
seenEnemyMarkers(vector<BoundingSphere>()),
seenPickupMarkers(vector<BoundingSphere>()),
weapons(vector<Gun*>()),
RoomKills(vector<int>()),
pathVisualisation(vector<Edge>()),
search(vector<int>()),
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 < 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;
}
它可能有一些做這件事?
for (int i = 0; i < 2; i++)
{
agents.push_back(Agent(100, *level, agents/*, level->Pickups()*/, D3DXCOLOR(1.0F, 0.4f, 0.4f, 1.0f), *mesh));
}
代理繼承自Brain。
這是代理:被實例化
的對象#ifndef AGENT_H
#define AGENT_H
#include <d3d10.h>
#include <d3dx10.h>
#include "Brain.h"
class level;
class Agent : public Brain
{
private:
int counter;
Level& 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& level,
vector<Agent>& agents,
D3DXCOLOR colour,
Mesh& mesh);
void UpdateAgent();
void DrawAgent(D3DXMATRIX matView, D3DXMATRIX matProjection, bool dataVis);
void RegenerativeHealth();
//int TargetChooser();
};
#endif
你是什麼意思,他們沒有影響?他們並沒有被執行? –
嘗試重建項目並再次調試 – Default
您能證明嗎? – jrok