I've got a class where one of the private properties is an instance of the class. In Java (because I'm used to Java) this looks like:
class Node {
private Node Pi;
}
And now I'm writing this in C++, and when I try to do the same thing, I get a red underline (I'm using Visual C++ 2010 Express), "Incomplete type is not allowed".
class Node {
private:
Node Pi; //Incomplete type is not allowed
};
I've tried fixing this by changing it to Node Pi(void);
but then why I try to use another function that modifies this property I get "Expression must be a modifiable lvalue".
class Node {
private:
Node Pi(void);
public:
void setPi(Node n);
};
void Node::setPi(Node n) {
Pi = n; //Node Node::Pi() expression must be a modifiable lvalue
}
Normally in Java there's no problem with this, so my question is, how do I implement this? I'm not a beginner to C++, but I haven't written with it for a while.
class Node {
private Node Pi;
void setPi(Node n) {
this.Pi = n;
}
}