print_add
is a non-static member function of foo
, which means it must be invoked on an instance of Foo
; hence it has an implicit first argument, the this
pointer.
Use a lambda that captures the foo
instance and invokes print_add
on it.
Foo foo;
test([&foo](int i){ foo.print_add(i); });
Another option is to use std::bind
to bind the foo
instance:
test(std::bind(&Foo::print_add, &foo, std::placeholders::_1));
Live demo
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…