Hi,
I'm writing a general Node class in C++ right now. I don't know how to make it having an ability to carry a general object. For example, I want my Node class could carry a general Object. It might be a "Book", a "Person" or an integer. I know in Java we got a Object class could solve this problem since all the classes in Java inherited from Object class. Is there any similar solution to this problem?
Here is my Java version solution, How could I convert it into c++? Thanks.
public class Node{
private Object item;
private Node next;
public Node(Object obj) {
item = obj;
}
public Object getItem() {
return this.item;
}
public Node getNext() {
return next;
}
public void setItem(Object obj) {
item = obj;
}
public void setNext(Node n) {
next = n;
}
}