mercredi 4 avril 2018

Cannot invoke template function [duplicate]

This question already has an answer here:

I am trying to invoke a template function, but get the error:

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);

Here is my implementation:

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)
}

What have I misunderstood?

Aucun commentaire:

Enregistrer un commentaire