Hey guys, I'm trying to solve an A* pathfinding problem, I've ran into a problem where I can't set a placeholder object to get filled in the constructor later
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
class Node{
public:
int coordX;
int coordY;
Node parent;
int distFromStart;
int heuristicDistFromTarget;
int totalCost;
Node(int, int, Node, int, int);
};
Node::Node(int mX, int mY, Node mParent, int dStart, int hDTarget){
coordX = mX;
coordY = mY;
parent = mParent;
distFromStart = dStart;
heuristicDistFromTarget = hDTarget;
totalCost = dStart + hDTarget;
}
When I set Node parent it won't let me, it says "Incomplete type not allowed". Any suggestions?
You can't have a Node contain another Node like that. Just imagine how big the node object would have to be. The node contains a node which contains another node which contains yet another node, and so on. The object would have to be infinitely big.
Consider using a pointer to the parent node instead.