如何创建一个带有指向父节点的指针的节点类,该父节点可以设置为空
How do I create a node class with a pointer to a parent node that I can make null
没关系,我是个白痴
当前节点类
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
相关文章:
- 函数无法识别我在C++传递节点指针向量?
- 交换树数据结构中根的 2 个子节点指针
- 父节点中的垃圾值
- C 不能将带有父类指针作为类型的静态模板成员定义引用
- 将子项复制构造到父类型指针中
- 如何将链表的节点直接链接到节点指针
- 在我的C++链表实现中取消引用节点指针,给出意想不到的结果
- 如何删除节点指针
- 查找二叉树的父节点函数
- 节点指针内的指针
- 从父节点中删除子节点 - PugiXML
- 无法返回节点指针
- 如何使运算符++继续到链表中的下一个节点指针
- 使用模板返回节点指针
- 霍夫曼树中的左节点和右节点指针不指向任何内容
- 使用节点指针数组来指向节点的子节点
- 简单C++指针:如何将子节点链接到父节点
- 如何创建一个带有指向父节点的指针的节点类,该父节点可以设置为空
- 试图创建一个指向父节点的指针,同时构建二叉树
- 从指针到成员恢复父节点