4 ms·
>std::shared_ptr<sf::RenderWindow> window; >std::shared_ptr<sf::Sprite> background, bird, pipeBottom, pipeTop; None of that should be shared_ptr, in fact they
by kiriin 4y ago
>std::shared_ptr<sf::RenderWindow> window;
>std::shared_ptr<sf::Sprite> background, bird, pipeBottom, pipeTop;
None of that should be shared_ptr, in fact they shouldn't be pointers at all.
>auto flappy = std::make_shared<FlappyBird>();
>flappy->run();
That would work just fine as a global in main.cpp
FlappyBird flappy;
- a_t48 4y agoDisagree - it's very reasonable for resources to be shared.
- ncmncm 4y agoIn most cases, not. Where there is a legitimate reason to share, share. Without, it is just sloppiness.
- a_t48 4y agoIn the context of a game engine, I mean. You may be sharing a model or texture between multiple entities, and want to know when it’s no longer in use.
- ncmncm 4y agoEven there, something higher up the stack probably knows too, and is in a better position to choose a good time to dispose of it.
- Shorel 4y agoThis is C++. You should not pay the performance hit for features you don't need in a particular program. In fact: It is reasonable for C++ programs to NOT use all language features.
- a_t48 4y agoI'm not disagreeing with you.
- ncmncm 4y agoOr, better, as an anonymous expression in main(): FlappyBird().run();