Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ Compilation error: Undefined identifier (for a function parameter)
    primarykey
    data
    text
    <p>I have a C++ class main.cpp in which I created a class like following:</p> <pre><code>class MapSearchNode { public: unsigned int x; // the (x,y) positions of the node unsigned int y; MapSearchNode() { x = y = 0; } MapSearchNode( unsigned int px, unsigned int py ) { x=px; y=py; } float goalDistance( MapSearchNode &amp;nodeGoal ); }; float MapSearchNode::goalDistance( MapSearchNode &amp;nodeGoal ) { float xd = fabs(float(((float)x - (float)nodeGoal.x))); float yd = fabs(float(((float)y - (float)nodeGoal.y))); return xd + yd; } int main{ //treatment } </code></pre> <p>And it works fine but then I wanted to seperate the class MyClass, so I created a MyClass.h and MyClass.cpp and seperated the code like following:</p> <p>MyClass.h</p> <pre><code>#ifndef _MAPSEARCHNODE_H #define _MAPSEARCHNODE_H class MapSearchNode { public: MapSearchNode(); MapSearchNode( unsigned int px, unsigned int py ); public: unsigned int x; unsigned int y; float goalDistance( MapSearchNode &amp;goalNode ); }; #endif </code></pre> <p>MyClass.cpp</p> <pre><code>#include "MapSearchNode.h" MapSearchNode::MapSearchNode():x(0), y(0)) {} MapSearchNode::MapSearchNode( unsigned int px, unsigned int py ):x(px), y(py) {} float MapSearchNode::goalDistance(MapSearchNode &amp;goalNode ){ float xDistance = fabs(float(((float)x - (float)goalNode.x))); float yDistance = fabs(float(((float)y - (float)goalNode.y))); return xDistance + yDistance; } </code></pre> <p>Bur when i try to compile i have an error:</p> <pre><code>Undefined identifier goalNode; //for the function goalDistance </code></pre> <p>Can someone please explain me why am I getting this error and how to fix it.</p> <p>EDIT: I hope I haven't forgotten anything now.</p> <p>EDIT: Well thanks a lot to those who downrated. Some of us are not experts like you and it's hard for them to see errors even small ones! </p>
    singulars
    1. This table or related slice is empty.
    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