I wrote a class Min-Max Heap Template Class which works perfectly fine with integers. As part of this data structure, i have to implement some sort of method to check for the smallest children/grandchildren of any given position in the Min-Max Heap array. Part of this method retrieves an item from my MinMaxHeap array at a specific position and then compare it to NULL. This works fine with integers. However i cannot(!) compare strings to NULL. I receive 100+ errors among the following lines:
Now, the compiler does this check at compile-time. Not at run-time. So checking if a template is a string or an integer is out of the question. Can i use anything else to fix this problem???
Here is my Function
As you can see i am attempting to check the template argument for strings, which of course doesn't work. So i am looking for some sort of other way to check both strings and integers for null :(
Any help is appreciated!
Code:
Error 1 error C2784: 'bool std::operator ==(const std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem *)' : could not deduce template argument for 'const _Elem *' from 'int' c:\documents and settings\dbm\my documents\visual studio 2005\projects\minmaxheap\minmaxheap\minmaxheap.cpp 261
Here is my Function
Code:
template <class Type> const int MinMaxHeap<Type>::findMinChild(const int pos) { /* Get left and right children of current position */ int lChildPos = getLChild(pos); int rChildPos = getRChild(pos); /* Get items at left and right positions */ Type itemAtLeft = getElementAtPos(lChildPos); Type itemAtRight = getElementAtPos(rChildPos); if (typeid(itemAtLeft) == typeid(string)) { if (itemAtLeft.size() == 0 || itemAtRight.size() == 0 || itemAtLeft < itemAtRight) return lChildPos; return rChildPos; } else { /* Compare both children and return the smallest */ compCount++; if (itemAtLeft == NULL || itemAtRight == NULL || itemAtLeft < itemAtRight) return lChildPos; return rChildPos; } }
Any help is appreciated!
Comment