It's a solution I came up with to a template specialization problem which is really crappy. And if there are any other, better, cleaner ways to do it, please enlighten me.
I have a templated node class with a lot of member variables and functions. With the exception of ONE member function, everything else is the same. For this one exceptional function, the behavior is different depending on what the template type is. So here's my solution:
One solution would be to change it into an inheritance relationship, but I'd have to change many other places in my program to conditional statements. So I'd like to avoid doing that.Code:class A; class B; template <typename T> class node { void recursive_function(node<A>* nt) { do_foo; recursive_function(nt); } void recursive_function(node<B>* nt) { do_bar; recursive_function(nt); } } //main body of program node<A>* na = new node<A>; node<B>* nb = new node<B>; na->recursive_function(na); nb->recursive_function(nb);
Is there a better way to do what I'm doing?