Created
October 14, 2014 19:59
-
-
Save commel/e3b3b0c8bcd7ce16a85a to your computer and use it in GitHub Desktop.
C++11 Functional parameter vs Haxe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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"); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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