I have the following:
void print_str(std::shared_ptr<std::string> str) {
std::cout << str->c_str() << std::endl;
}
int main() {
auto str = std::make_shared<std::string>("Hello");
std::function<void()> f = std::bind(print_str, str);
f(); // correctly print: Hello
return 0;
}
I think the type of std::bind(print_str, str)
is std::function<void(std::shared_ptr<std::string>)>
, but the code above is correctly running. Is there any trick in std::bind
?
env: centos, gcc82
Aucun commentaire:
Enregistrer un commentaire