struct Foo {
Foo(int num) : num_(num) {}
void print_add(int i) const { std::cout << num_+i << '\n'; }
int num_;
};
int main ()
{
function<void(const Foo*, int)> func = &Foo::print_add;
function<void(const Foo&, int)> func2 = &Foo::print_add;
Foo f(1), f2(2);
func(&f, 2);
func2(f2, 3);
return 0;
}
why func and func2 both can call member function Foo::print_add correctly? they have different callable type as template argument. From what I know, ‘this’ pointer is passed as a hidden argument to all nonstatic member function calls, the callable type of func2 recieve const Foo& as argument which doesn't match the type of this pointer. why the code above doesn't generate a compiler error?