gpt4 book ai didi

c++ - 如何创建一个节点类,该节点类带有指向我可以设为 null 的父节点的指针

转载 作者:行者123 更新时间:2023-11-28 03:17:45 25 4
gpt4 key购买 nike

别介意我是个白痴

我当前的节点类

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' is undefined 错误

最佳答案

C++ 中没有null。有 NULL , 有 0 并且有 nullptr在 C++11 中。

关于c++ - 如何创建一个节点类,该节点类带有指向我可以设为 null 的父节点的指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16327487/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com