I tried figuring this problem out with no luck, so hopefully it's not a duplicate.
I've implemented the A* pathfinding algorithm for a uni project in an SDL based graphical "game", in which you choose the starting and ending point, and the algorithm figures the path out and puts in it an STL vector.
The problem is that I can declare the vector in the cpp file no problem, but I need it to be in the header file, because I need to reuse it in other places, but if I declare the exact same vector in the header, it says "undeclared identifier", even if I clearly included the library, since it works in the cpp file.
This is the MapSearchNode class:
#ifndef MapSearchNode_hpp
#define MapSearchNode_hpp
#include "stlastar.h"
#include "map.hpp"
class MapSearchNode
{
public:
int x; // the (x,y) positions of the node
int y;
MapSearchNode() { x = y = 0; }
MapSearchNode( int px, int py ) { x=px; y=py; }
float GoalDistanceEstimate( MapSearchNode &nodeGoal );
bool IsGoal( MapSearchNode &nodeGoal );
bool GetSuccessors( AStarSearch<MapSearchNode> *astarsearch, MapSearchNode *parent_node );
float GetCost( MapSearchNode &successor );
bool IsSameState( MapSearchNode &rhs );
void PrintNodeInfo();
};
#endif
And this is the Game class, which has the actual A* and game code in the cpp file
#ifndef Game_hpp
#define Game_hpp
#include <iostream>
#include <vector>
#include "SDL2/SDL.h"
#include "SDL2_image/SDL_image.h"
#include "textureManager.hpp"
#include "gameObject.hpp"
#include "map.hpp"
#include "MapSearchNode.hpp"
class Game{
public:
Game();
~Game();
void init(const char* title, int xpos, int ypos, int width, int height, bool fullscreen);
void handleEvents();
void update();
void render();
void clean();
int gethRes(){return hRes;};
int getvRes(){return vRes;};
bool isRunning(){return running;};
static SDL_Renderer* renderer;
private:
int hRes = 640;
int vRes = 640;
bool running; //Se il gioco sta girando o no.
SDL_Window *window; //Finestra del gioco
const int startX = 4;
const int startY = 3;
const int endX = 19;
const int endY = 3;
};
#endif /* Game_hpp */
If I try to declare:
std::vector<MapSearchNode*> directions;
in this header file, it gives me the error.