Member function overloading/template specialization issue
- by Ferruccio
I've been trying to call the overloaded table::scan_index(std::string, ...) member function without success. For the sake of clarity, I have stripped out all non-relevant code.
I have a class called table which has an overloaded/templated member function named scan_index() in order to handle strings as a special case.
class table : boost::noncopyable
{
public:
template <typename T>
void scan_index(T val, std::function<bool (uint recno, T val)> callback) {
// code
}
void scan_index(std::string val, std::function<bool (uint recno, std::string val)> callback) {
// code
}
};
Then there is a hitlist class which has a number of templated member functions which call table::scan_index(T, ...)
class hitlist {
public:
template <typename T>
void eq(uint fieldno, T value) {
table* index_table = db.get_index_table(fieldno);
// code
index_table->scan_index<T>(value, [&](uint recno, T n)->bool {
// code
});
}
};
And, finally, the code which kicks it all off:
hitlist hl;
// code
hl.eq<std::string>(*fieldno, p1.to_string());
The problem is that instead of calling table::scan_index(std::string, ...), it calls the templated version. I have tried using both overloading (as shown above) and a specialized function template (below), but nothing seems to work. After staring at this code for a few hours, I feel like I'm missing something obvious. Any ideas?
template <>
void scan_index<std::string>(std::string val, std::function<bool (uint recno, std::string val)> callback) {
// code
}