suppose i’m implementing a polymorphic tree data structure that can take on data of any type…
Tree<Int> or Tree<String> or Tree<Object>
but I’m implementing it in C++….how would I specify that the tree can contain an arbitrary type similar to generics in Java
also is there an equivalent of Java’s Object object in C++ in which all objects in C++ inherits Object
The nearest equivalent of Java’s generic is template in C++. Its not equivalent as such, if strictly speaking. But that is what you’ve in C++. So to suit your need, you’ve to work a little bit so that you can write equivalent code in C++.
Here’re few links to some articles that compare C++ template with Java generics: