Skip to content

Instantly share code, notes, and snippets.

@commel
Created October 14, 2014 19:59
Show Gist options
  • Select an option

  • Save commel/e3b3b0c8bcd7ce16a85a to your computer and use it in GitHub Desktop.

Select an option

Save commel/e3b3b0c8bcd7ce16a85a to your computer and use it in GitHub Desktop.
C++11 Functional parameter vs Haxe
#include <iostream>
#include <string>
#include <functional>
class Sayer {
public:
void say(std::function<void(std::string)> func, std::string data) {
func(data);
}
};
int main() {
Sayer s;
s.say( [](std::string text) { std::cout << text << std::endl; },
"Hallo Welt");
}
package app;
class Sayer {
public function new() {}
public function say(func: String->Void, text:String) {
func(text);
}
}
class Main {
static function main() {
var s = new Sayer();
s.say(function(a:String) { return Sys.println(a); }, "Hallo Welt");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment