SFML community forums

General => General discussions => Topic started by: xqbt on March 20, 2016, 12:56:57 am

Title: SFML Game Development book - bug in the sources?
Post by: xqbt on March 20, 2016, 12:56:57 am
So I am reading a book called SFML Game Development (and I really like it), but I think I might have found a major memory leak in the provided sources. If you go to the main repository and check this file:
https://github.com/SFML/SFML-Game-Development-Book/blob/master/10_Network/Include/Book/SceneNode.hpp
you will see that there is no virtual destructor declared. I suppose that's a bug.
Please, fix me if I am wrong.
Title: Re: SFML Game Development book - bug in the sources?
Post by: Nexus on March 20, 2016, 09:25:17 am
The base classes sf::Transformable and sf::Drawable have a virtual destructors.
Title: Re: SFML Game Development book - bug in the sources?
Post by: xqbt on March 20, 2016, 10:03:39 am
OK, got it, thank you. It was dumb of me not to think of that.
Title: Re: SFML Game Development book - bug in the sources?
Post by: Laurent on March 20, 2016, 10:06:44 am
Isn't it a good practice to explicitly declare a destructor virtual for an abstract base class, regardless of its own parents? It's clearer for users, and less prone to errors when the code evolves (the parent classes may change, or not be parents anymore). It's like not including a standard header, because you know that some other that you already include does it :P
Title: Re: SFML Game Development book - bug in the sources?
Post by: Nexus on March 20, 2016, 10:14:19 am
It arguably is. :P

Declaring ABC destructors virtual can make sense, the same way that e.g. declaring constructors explicit by default or using override can. It's redundant, but helps prevent errors when migrating code.