我有一个代表游戏中捕捉区域的类。这里面类的我有玩家被捕获区的载体(CUtlVector是我使用的SDK载体类)C++通过引用传递一个对象?
typedef CUtlVector<ConquestPlayer*> CappingPlayersType; (defined outside of class)
CappingPlayersType CapturePlayers;
在我的游戏管理器类,我想检索玩家的捕捉名单使用此代码。
void GameManager::UpdateCaptureData()
{
// Loop Active Capture Points
for(int i = 0; i < CaptureZones.Count(); i++)
{
// Get List of Active Players Capturing this Point
CappingPlayersType *CapturePlayers = NULL;
int CapPlayersCount = CaptureZones.Element(i)->GetPlayersCapturing(CapturePlayers);
int CTriggerCaptureZone::GetPlayersCapturing(CappingPlayersType &CapPlayers)
{
CapPlayers = CapturePlayers;
return CapturePlayers.Count();
}
它已经有一段时间了,我不记得从函数中检索列表并将其存储在局部变量中的最佳方法。 IIRC由于CapturePlayers对象为NULL,所以我无法通过引用传递,但是我不知所措。任何帮助将非常感激。
你的代码有点令人困惑。看起来好像总是向GetPlayersCapturing函数传递一个空指针,然后试图将它强制转换为引用。你能否更详细地解释你想要做什么,以及为什么CapturePlayers总是NULL? – Cam 2010-12-11 01:22:43