I am from Java background. My java class:
class Node {
public Node left;
public Node right;
public int deep;
public Point p; //another class
}
When I tried to convert it into C++, I faced error: Field has incomplete type Node. So, based on some online help, I converted it to following:
class Node {
public:
Node* left;
Node* right;
int deep;
Point p; //another class
}
But my other part of code breaks now. The java code was:
Node pathNode = new Node();
if (pathNode.left == null) {
pathNode = pathNode.left;
}
I really want to know how to implement it in C++. My try so far in C++:
class Node {
public:
Node* left;
Node* right;
int deep;
Point p;
Node() {
this->left = nullptr;
this->right = nullptr;
this->deep = NULL; // not sure correct or wrong
this->p = NULL // not sure correct or wrong
}
then other part of c++ code:
Node pathNode;
if (pathNode.left == nullptr) {
pathNode = pathNode.left; //<== here i am stuck exactly.
}
OR if there is any better way, you can suggest me. Moreover, how to set class members to NULL or nullptr?