[Solved] Pointer gives me the address rather than the value;


OK, now I think you’ve finally posted the code that has the problem

class ZombieLand : public Singleton<ZombieLand>
{
    DECLARE_SINGLETON(ZombieLand);
public:
    MachineState* world[19][19];
    bool map[19][19];

    MachineState* getField(int x, int y)
    {
        return world[x][y];
    }
    void setWorld(MachineState state)
    {
        world[state.x][state.y] = &state;
        map[state.x][state.y] = true;
    }
};

This is undefined behaviour because you are saving the pointer to a local variable state. The state variable gets destroyed after you have exited the setWorld function, so your world array is just holding pointers to destroyed objects, That’s why you have garbage values.

Rewrite this class without pointers.

class ZombieLand : public Singleton<ZombieLand>
{
    DECLARE_SINGLETON(ZombieLand);
public:
    MachineState world[19][19];
    bool map[19][19];

    MachineState* getField(int x, int y)
    {
        return &world[x][y];
    }
    void setWorld(const MachineState& state)
    {
        world[state.x][state.y] = state;
        map[state.x][state.y] = true;
    }
};

Pointers are almost always a bad idea, you should try to write code without them.

Got there in the end at least.

0

solved Pointer gives me the address rather than the value;