Suppose I have this class:
template<class K, class Compare>
class findMax {
K* keyArray; // Supposed to be an array of K.
int size;
public:
findMax (K n, Compare init); // Here I would like to initialize the array.
~findMax ();
K& Find(K key, Compare cmp); // Return an elemnt in the array according to a condition.
void printArray(Compare print); // Print the array according to a condition.
};
I want each cmp
function to be different when I implement the constructor, Find
and printArray
.
For example:
template<class K, class Compare>
findMax<K, Compare>::findMax(int n, Compare init) {
keyArray = new K [n];
init(keyArray, n);
}
where init
is a function I implement in my source file, like this for example:
// Init will initialize the array to 0.
void init (int* array, int n) {
for (int i=0; i<n; i++)
array[i] = 0;
}
Although, I want to be able to send a different function to Find
for example, that compares between two elements. I'm having trouble figuring out how because when I create a new findMax
object, like findMax<int, UNKNOWN> f
, what do I put instead of UNKNOWN
?