Note that there are some explanatory texts on larger screens.

plurals
  1. POPointer gives me the address rather than the value;
    primarykey
    data
    text
    <pre><code>class ZombieLand : public Singleton&lt;ZombieLand&gt; { 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] = &amp;state; map[state.x][state.y] = true; } }; struct MachineState { template &lt;typename MachineTraits&gt; 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 GetTruth() const throw() { return m_InfectOnAttack; } void setPoint(Point p1, Point p2, Point p3) { point1=p1; point2=p2; point3=p3; } }; </code></pre> <p>I later call the getField function by doing</p> <pre><code>MachineState *Field1 = ZombieLand::get().getField(state.x, state.y-1 ); </code></pre> <p>The problem is that when i try to access a member by doing Field1->getTruth() it's returning me the address of the pointer rather than the actual value(false or true). I don't understand why this is happening</p> <pre><code>template &lt;class T&gt; class Singleton { private: static T* _instance; protected: Singleton() {} public: static T&amp; get() { if (_instance) { return *_instance; } else { _instance = new T(); return *_instance; } } }; if(ZombieLand::get().map[state.x+2][state.y] == true) { MachineState *field3 = ZombieLand::get().getField(state.x+2, state.y); std::cout&lt;&lt;"FOUND FIELD"&lt;&lt;Field3-&gt;getTruth(); } </code></pre> <p>when this if statement becomes true it prints "FOUND FIELD 0246" onto my console</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload