无法调用模板功能

时间:2018-04-04 22:18:42

标签: c++ c++11 templates

我正在尝试调用模板函数,但得到错误:

error: no matching member function for call to 'getRecord'
  return getRecord(player, myVoidPtr,
         ^~~~~~~~~
./file.h:90:15: note: candidate template ignored: could not match 'function<type-parameter-0-0 (char *)>' against
      '(lambda at file.cc:55:5)'
  const char *getRecord(const T& item, void *filePtr, std::function<T(char*)> parseFn);

这是我的实施:

const char *getPlayerRec(const std::string& player) {
  return getRecord(player, myVoidPtr,
    [](const char *record) {
      return string(record);
    }
  );
}

template <typename T>
const char *getRecord(const T& item, void *filePtr, std::function<T(char*)> parseFn) {
  // (elided)
}

我误解了什么?

0 个答案:

没有答案