Template help, like Comparable in Java

Hello, I'm new to C++, coming from mostly Java. I'm trying to implement a binary tree, and I want the Node class to have a key and value type, using templates. I have found that instead of the Comparable<X> interface in Java one uses the < operator. How do you specify this in the template?

template<class K, class V>
class Node
{
...
}

So how do I specify in the template, that the class K needs to have the < operator?
You don't. You simply write the class assuming that K has an operator<() overload. If it doesn't, the user will get a compiler error.
Last edited on
Operator overloading is something that is missing from Java language. So is multiple inheritance but it can be mitigated using interfaces.
Thanks!
Topic archived. No new replies allowed.