I am getting an "unresolved overloaded function type" error when trying to pass an overloaded static function to an std::function
.
I am aware of similar questions, such as this and this. However, even though the answers there work for getting the address of the right function into a function pointer, they fail with std::function
. Here is my MWE:
#include <string>
#include <iostream>
#include <functional>
struct ClassA {
static std::string DoCompress(const std::string& s) { return s; }
static std::string DoCompress(const char* c, size_t s) { return std::string(c, s); }
};
void hello(std::function<std::string(const char*, size_t)> f) {
std::string h = "hello";
std::cout << f(h.data(), h.size()) << std::endl;
}
int main(int argc, char* argv[]) {
std::string (*fff) (const char*, size_t) = &ClassA::DoCompress;
hello(fff);
hello(static_cast<std::string(const char*, size_t)>(&ClassA::DoCompress));
}
Could someone explain why the static_cast
doesn't work when the implicit one does?
Aucun commentaire:
Enregistrer un commentaire