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

标签 c++

别介意我是个白痴

我当前的节点类

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/

相关文章:

c++ - inotify/带有 NFS 的工具

c++ - 相互了解的对象集合

c# - 从 C++ 库方法返回的 "char*"获取 C# 字符串?

c++ - 如何在 wxWidgets 应用程序中获取 Internet Explorer?

c++ - 将数据从 C++ 类传递到 Xcode 中的 Objective-C 类

c++ - STL排序算法

c++ - 链接: fatal error LNK1561: entry point must be defined VS2015 developer cmd window

c++ - Valgrind 下 Mac OS 上的 std::thread.join() SIGSEGV

c++ - 如何使用模板模板参数为该方法不需要通用接口(interface)的 STL 容器实现通用方法

c++ - 重定向 boost 绑定(bind)