Created
November 6, 2015 03:31
-
-
Save omochi/3868fe6e88c504affee7 to your computer and use it in GitHub Desktop.
This file contains 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
// with gcc 4.8.2 | |
#include <cstdio> | |
#include <functional> | |
int death = 1; | |
class Cat { | |
public: | |
std::function<void()> callback_; | |
void nya(); | |
}; | |
class App { | |
public: | |
Cat * cat_; | |
void main(); | |
}; | |
void Cat::nya() { | |
callback_(); | |
} | |
void App::main() { | |
cat_ = new Cat(); | |
cat_->callback_ = [this] { | |
auto this2 = this; | |
delete cat_; | |
if (death) { | |
cat_ = nullptr; | |
} else { | |
this2->cat_ = nullptr; | |
} | |
printf("ok\n"); | |
}; | |
cat_->nya(); | |
} | |
int main(int argc, char * argv[]) { | |
App * app = new App(); | |
app->main(); | |
delete app; | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
gcc5.2でもダメ。clang3.7はいけた。