저는 계속 움직이는 객체를 보관해야하는 2D 치수 배열을 가지고 있습니다.2D 배열의 객체가 Null인지 확인합니다.
class ZombieLand : public Singleton<ZombieLand>
{
DECLARE_SINGLETON(ZombieLand);
public:
MachineState world [19][19];
MachineState getWorld()
{
std::cout<<"World";
return world[19][19];
}
void setWorld(MachineState & state)
{
world [state.x][state.y] = state;
}
}
내 질문은 0
switch (state.m_Facing)
{
case (MachineState::UP):
if(ZombieLand::get().world[state.x][state.y-1] != NULL)
{
state.m_occupied = true;
break;
}
가 어떻게이 있는지 확인할 수 있습니다 나는 특정 위치에 Null이 있는지 확인하려고하지만, "NULL"단어가 작동하지 않으며, 수행 내 세계 배열의 위치가 이미 객체를 보유하고 있습니까? 미리 감사드립니다.
내 MachineState 클래스
struct MachineState
{
template <typename MachineTraits>
friend class Machine;
enum Facing { UP, RIGHT, DOWN, LEFT};
MachineState()
: m_ProgramCounter(1)
, m_ActionsTaken(0)
, m_Facing(UP)
, m_Test(false)
, m_Memory(nullptr)
,x(0)
,y(0)
,point1(25, 10)
,point2(10, 40)
,point3(40, 40)
{ }
int m_ProgramCounter;
int m_ActionsTaken;
Facing m_Facing;
bool m_Test;
bool m_occupied;
int x;
int y;
Point point1;
Point point2;
Point point3;
int GetActionsPerTurn() const throw() { return m_ActionsPerTurn; }
int GetMaxMemory() const throw() {return m_MaxMemory; }
bool GetInfect() const throw() { return m_InfectOnAttack; }
void setPoint(Point p1, Point p2, Point p3)
{
point1=p1;
point2=p2;
point3=p3;
}
};
어떻게'MachineState'가 정의 되었습니까? 'MachineState' 유형의 객체에 대해'포인터 '의 2 차원 배열을 만드는 것을 고려 했습니까? –
FYI 싱글 톤이 좋지 않습니다. 매크로가 좋지 않습니다. – David
@Dave 감사합니다. 방금 책을 읽었습니다. 전역 변수를 선언하는 것보다 더 낫다고 말하면서 구현해 보겠습니다. –