Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/154.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 空安全等于C+中的运算符+;_C++ - Fatal编程技术网

C++ 空安全等于C+中的运算符+;

C++ 空安全等于C+中的运算符+;,c++,C++,考虑以下代码: BST.h #ifndef BST_H #define BST_H #include <iostream> typedef char Key; typedef int Value; #define NULL 0 class BST{ private: class Node{ Key key; Value value; Node* left; Node* right; int N; pu

考虑以下代码:

BST.h

#ifndef BST_H
#define BST_H

#include <iostream>

typedef char Key;
typedef int Value;
#define NULL 0

class BST{

private:
    class Node{
      Key key;
      Value value;
      Node* left;
      Node* right;
      int N;
    public:
      Node(Key key='A',Value value=NULL,Node* left=NULL,Node* right=NULL,int N=0):
      key(key),value(value),left(left),right(right),N(N)
      {
       std::cout << "(Node created) Key: " << key << " Value : " << value << std::endl; 
       N++;
      }
      int getN()
      {
       return N;
      }
      bool operator==(Node& node)
      {

          if (this->key == node.key && this->value == node.value && this->left == node.left && 
              this->right == node.right && this->N == node.N)
              return true;
          else
              return false;
      }
    };

Node& Root;

public:

    int size();
    int size(Node& node);

};


#endif
解决此错误的一种方法是将equal to运算符更改为:
bool操作符==(节点*节点)

当我将节点作为引用传递时,如何解决此错误。
bool操作符==(节点和节点)


谢谢

节点
是一个参考,所以它永远不能是
NULL
0

如果(节点==NULL),你想用
测试什么?如果是“默认值”,则可以使用
If(node==node())
。值不能为NULL,只有左侧和右侧的值可以为NULL,因为它们是唯一的指针。
#include "BST.h"
#include <iostream>


int BST::size()
{
 return size(Root);
}

int BST::size(Node& node)
{
 if(node == NULL)//here
     return 0;
 else
     return node.getN();
}
bst.cpp(12): error C2679: binary '==' : no operator found which takes a right-hand operand of type 'int' (or there is no acceptable conversion)
1>          c:\users\gaurav1.k\documents\visual studio 2010\projects\bst\bst\bst.h(30): could be 'bool BST::Node::operator ==(BST::Node &)'
1>          while trying to match the argument list '(BST::Node, int)'