reflaxe.CPP
reflaxe.CPP copied to clipboard
function bind was wrong.
class Test {
public function new() {
}
public function say(){
trace('hello world');
}
}
....
var test4=new Test();
var fn=test4.say;
fn();
and get this cpp code
std::shared_ptr<Test> test4 = std::make_shared<Test>();
std::function<void()> fn = test4->say;//wrong here
fn();
should be
std::function<void(void)> fn = std::bind(&Test::say, test4);
// or which is the better choose?
auto fn2 = std::mem_fn(&Test::say);
fn2(test4.get());
Oooh, nice catch!! I like your solutions too! Wasn't aware of those functions and will definitely use those!!
I was initially thinking to just generate a lambda. But that'd look worse. XD
auto fn2 = []() { test4->say(); };