Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Virtual final functions?  (Read 1057 times)

0 Members and 1 Guest are viewing this topic.

cheesesteak

  • Newbie
  • *
  • Posts: 4
    • View Profile
Virtual final functions?
« 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?
« Last Edit: February 19, 2014, 07:30:41 pm by cheesesteak »

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Virtual final functions?
« Reply #1 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

cheesesteak

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Virtual final functions?
« Reply #2 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!