I am writing a code which uses templates to support int datatype and char* datatype. lets say
struct node {
KeyType key;
struct node *next;
};
And this is sorted linked list node, so whenever I insert node, I have to compare. For this I created one header file comparison.h, in which I have defined comparison operation like
LT(a,b)..
GT(a,b)..
And when I use node<int> I define LT(a, b) as a<b and in case of node<char*> strncmp(a, b, SIZE) ( Using macro I switch the definition )
So Is there any way by which I minimally interfere this comparison.h. What should be the better ways of using comparison or specific operations specific to datatypes when using templates ?
Use template specialization. For example:
The output will be: