gpt4 book ai didi

c++ - 我怎样才能让这个函数返回null?

转载 作者:太空宇宙 更新时间:2023-11-04 15:06:18 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
C++ return a “NULL” object if search result not found

我试图在特定条件下返回 NULL,但它不允许我这样做,为什么不,我怎样才能让它返回空值或 0?

struct Entity
{
USHORT X;
USHORT Y;
UINT Serial;
USHORT SpriteID;
EntityType Type;
Direction FacingDirection;
};

函数是:

Entity& GetEntityAt(int index)
{
if (!GameObjects.empty())
{
lock_guard<mutex> lock(PadLock);
Entity& result = GameObjects[index];
return result;
}
return NULL; // <- this won't compile
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com