• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Gamer Gamester

C++: Subclass destructors... is the virtual inherited?

7 posts in this topic

Quick question. So I have a base class, and I make the destructor virtual to make sure any inherited classes are cleaned up properly:
class Base
{
  virtual ~Base() {}
}
Now, if I make a child class that inherits from Base, and it doesn't need to deallocate anything for itself, do I need to explicitly make another empty virtual destructor so that any further subclasses get cleaned up, or does the virtual carry through from the Base. Example:
class Sub : public Base
{
  // Various methods, but nothing to clean up so no destructor
}

class SubSub: public Sub
{
  ~SubSub();  // This has a destructor!!  Now if I call delete on a Base*,
              // will this destructor still get called without Sub also
              // having a virtual destructor?
}
I know I could just be safe and put a virtual destructor in each class, but I like to have minimal code, I find it makes everything easier.
0

Share this post


Link to post
Share on other sites
Yes, virtual will implied for the version in derived classes. This applies to all functions declared virtual in the base class.
0

Share this post


Link to post
Share on other sites
Thanks.

To make sure I have a grasp on this: The virtual is implied for all functions in derived classes if these derived classes don't override the functions. Is this true also if the function is overridden? Or do I need to mark the overridden version virtual?

(In other words, from my previous example, should SubSub's destructor be virtual to "continue the virtuality"?)
0

Share this post


Link to post
Share on other sites
Hmm... the faq seems to make it seem as if once a method is declared virtual, it will remain virtual in all overridden versions, even if they're not marked virtual.

This comes as a surprise to me, as I recall reading in a recent book that you have to explicitly mark later versions virtual as well, or the "virtualness" ends there.

Perhaps the book I was reading was incorrect/out of date?
0

Share this post


Link to post
Share on other sites
Quote:
Hmm... the faq seems to make it seem as if once a method is declared virtual, it will remain virtual in all overridden versions, even if they're not marked virtual.

That's correct

Quote:
Perhaps the book I was reading was incorrect/out of date?

Very possibly. C++ has existed since the mid 1980s, but was only standardised in 1997. Anything written before then is most liekly useless. It's also a very complicated language - many of the people writing about it on the internet aren't expert and make mistakes. The C++ FAQ Lite is a trustworthy source though.
0

Share this post


Link to post
Share on other sites
Ah, this site explains this very clearly:
IBM Reference
It's the reference for IBM's AIX C++ Compiler, but I assume (perhaps foolishly[wink]) it follows the standard pretty close.

In particular this line covers it (B is subclass of A):
Quote:
If you declare a function named f in class B with the same name and same parameter list as A::f, then B::f is also virtual (regardless whether or not you declare B::f with the virtual keyword) and it overrides A::f.


Out of curiosity, does anybody recommend a good reference for C++ that complies with the standard? (though the standard will change soon with C++0x) Is Stroustrup's book best for that? I've been meaning to get it regardless but am waiting for the time being as it's a tad pricey. There's also the actual standard which you can download, is that a good idea? I'm concerned it'll be filled with stuff that's mostly of use to people creating/maintaining compilers and not so much for programmers who just want to use the language.
0

Share this post


Link to post
Share on other sites
Maybe take a look at one of Herb Sutter's Exceptional C++ books. They might be a little cheaper and will definitely be a good source of standards conformant information (Sutter is the chair of the ISO C++ committee). Also, Andrei Alexandrescu's Modern C++.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0