Ok, so I'm to write a template linked list class. The list is implemented using node structs defined as:
1 2 3 4 5
struct Node
{
Object* data;
Node* next;
};
where Object is the variable data type. I'm to write a BuildList function for the class that takes an ifstream object as a parameter and creates the list using insertion sort. The data that's to be read from the file (i.e. one line of the file) for one Node's data (of type Object) will be either an int and a char (two values, sorted in numerical order by the int) or two strings and two ints (sorted alphabetically by the first string).
I could create a template class specialization specifically for the Object of four values (string, string, int, int) that has a BuildList function that stores four values in data and write the original template class's BuildList function to store two values (int, char), but that seems like it would defeat the purpose of using a template class in the first place and would be entirely too redundant, having to rewrite the entire class as a specialization just for one function.
I guess I was wondering if it's possible to specialize just the BuildList function, unless there's some way to do this that I can't think of (multiple constructors, perhaps?). Tips appreciated.