Hi, im building an implementation of the A* path finding algrithm, and i have a class which is basically an interface for a linked list
now this is my first ever attempt at programming c++ and my first ever class, but it would seem logical that struct Point should be inside the linkedPointList class, however then if i want to use the getPoint function outside of that class, struct point isnt defined and it wont work. Is there a way around this, and if there isnt what would be common practice when a situation like this occurs. Should i make separate functions for getx, gety, get value, or should i return it as an array?Code:#include <cstdlib> #include <iostream> using namespace std; // these are used to create linked lists of open points availible for testing struct point { int x; int y; int value; point *next; }; class linkedPointList { private: point *start; point *end; point *cur; int length; public: void appendPoint(int x,int y) { end->next = new point; end = end->next; end->x = x; end->y = y; end->value = 0; end->next = 0; printf("%d\n",end->x); length++; } point * getPoint(int pNum) { cur = start; for(int i = 0; i <= pNum; i++) { cur = cur->next; } return cur; } linkedPointList() { start = new point; start->next = 0; cur = start; end = start; length = 0; } }; int main(int argc, char *argv[]) { linkedPointList test; test.appendPoint(1,2); test.appendPoint(3,4); point *testPoint; testPoint = test.getPoint(0); printf("%d\n",testPoint->x); system("PAUSE"); return EXIT_SUCCESS; }



LinkBack URL
About LinkBacks




