如何创建一个带有指向父节点的指针的节点类,该父节点可以设置为空

How do I create a node class with a pointer to a parent node that I can make null

本文关键字:父节点 指针 节点 设置 创建 何创建 一个      更新时间:2023-10-16

没关系,我是个白痴

当前节点类

class node
{
public:
    int xCoord;   // current position
    int yCoord;
    int gCost;     //Cost to travel to node
    int hCost;
    int parentX;  // parent coordinates
    int parentY;
    node* parentNode;
    node(int x, int y, int g , int h, int pX, int pY, node* parent) 
        {xCoord=x; yCoord = y; gCost = g; hCost = h; parentX = pX; parentY = pY;   parentNode = parent;}
    int getxCoord() const {return xCoord;}
    int getyCoord() const {return yCoord;}
    int getgCost() const {return gCost;}
    int getfCost() const {return hCost;}
    int getparentX() const {return parentX;}
    int getparentY() const {return parentY;}

我想创建一个像这样的节点

node* startNode = new node(startX, startY, 0, 0, 0, 0, null)

然而,它给了我一个标识符'null'是未定义的错误

c++中没有null。c++ 11中有NULL,有0,有nullptr