Code is as the following.
std::string::empty()
should take the this
pointer as the parameter whose type is pointer, std::string *
.
How could the calling at line 2
and 3
be OK?
#include <iostream>
#include <functional>
int main() {
std::string str{"A small pond"};
std::function<bool(std::string*)> fp = &std::string::empty;
std::cout << fp(&str) << std::endl; // 1
std::function<bool(std::string)> f = &std::string::empty;
std::cout << f(str) << std::endl; // 2
std::function<bool(std::string&)> fr = &std::string::empty;
std::cout << fr(str) << std::endl; // 3
}
/*
output:
0
0
0
*/
clang version 9.0.0-2~ubuntu18.04.2 (tags/RELEASE_900/final)
g++ (Ubuntu 8.4.0-1ubuntu1~18.04) 8.4.0