SFML community forums

Help => General => Topic started by: cheesesteak on February 19, 2014, 07:27:06 pm

Title: Virtual final functions?
Post by: cheesesteak on February 19, 2014, 07:27:06 pm
Hey everybody,

while enjoying the book "SFML Game Development", I came across some code (page 58), which I really don't understand. In the header file of the class SceneNode, which publicly inherits from sf::Drawable, it says:

virtual void draw(...) const;

The reader is being recommended declare draw(...) with the C++0x final keyword, which I think makes sense. (I would also recommend the override keyword.)

Question: Why do they use the virtual keyword? I mean, draw(...) is being inherited from sf::Drawable, but that doesn't require the use of virtual, does it? Furthermore, virtual implies that the function is designed to be overridden, which clearly isn't the case (as implied by final)...

Is this an error or do I just not understand what's going on?
Title: Re: Virtual final functions?
Post by: G. on February 19, 2014, 07:36:52 pm
When you inherit a virtual function, it's virtual anyway, even if you don't write virtual in front of it.
Since it's virtual, why not writing it explicitly? :p
Title: Re: Virtual final functions?
Post by: cheesesteak on February 19, 2014, 08:43:42 pm
That does make a lot of sense, I don't know what is wrong with me these days...  :-X  ;)

Thank you very much!