Template Class and by Key comparison

closed account (Lv0f92yv)
I am writing a binary search tree (currently finished, minus generic support), and am interested in making it a generic class (presumably using templates), that takes an object only if the object can sort itself by it's key. This will be done in my other object's class that I wrote (I will provide the key/comparison method).

How do I write the BST class such that it works for any object that implements a comparison interface? (That I can also write if needed). I have done this in Java, but would like to know the C++.

Java class declaraton: public class Myclass<O extends Comparable<K>>

where comparable is the interface used to specify that each object O must implement a method specified in the comparable interface that defines how an object O is compared to other O's.

Thanks in advance.
Last edited on
Simply call operator< (or whatever) on type T. If type T doesn't implement it, then the
code will fail to compile.
closed account (Lv0f92yv)
So would it look like

class Myclass < T operator < > as the declaration? Doesn't look right...
Topic archived. No new replies allowed.