News for hackers. Stuff that matters.
Re:Pure virtual destructors in C++ by joelburget on Sunday November 14, 2010 @04:10PM (#1904164)
It's exactly this kind of thing that lead me away from C++. There are far too many gotcha's and tricks you need to know to write good C++.
Re:Pure virtual destructors in C++ by android2 on Sunday November 14, 2010 @01:57PM (#1903841)
"To work correctly, classes with virtual methods must also have virtual destructors."

Not a good way to start the article... I immediately question the author's credibility following this statement.

Re:Pure virtual destructors in C++ by tomjen3 on Sunday November 14, 2010 @02:16PM (#1903890)
Why? If they don't it is going to mess up the destruction sequence if they are ever stored and then released polymorphically, such as from a collection of pointers to classes.

What he is saying is standard C++ knowledge.

Re:Pure virtual destructors in C++ by Rexxar on Sunday November 14, 2010 @03:00PM (#1903993)
You can also use a protected non-virtual destructor in the base class to avoid to mess up the destruction sequence. But what he says is indeed the most common case.
Re:Pure virtual destructors in C++ by _stephan on Sunday November 14, 2010 @02:57PM (#1903984)
Sometimes an alternative is to make the destructor in the base class protected.
Re:Pure virtual destructors in C++ by jimwise on Sunday November 14, 2010 @02:29PM (#1903922)
All of which is a workaround for the fact that there is no explicit way to declare a c++ class to be abstract-only.

What happens if you do have shared logic to put in the abstract base class's destructor? It can't be pure virtual, and you're back to being able to instantiate your 'abstract' base class...

Re:Pure virtual destructors in C++ by thought_alarm on Sunday November 14, 2010 @03:39PM (#1904071)
> All of which is a workaround for the fact that there is no explicit way to declare a c++ class to be abstract-only.

Sure you can. Just put the word "Abstract" in the class name, and then every programmer who reads that class name will know that it's abstract. What more does one need?

That approach is much clearer than resorting to tricks like a pure virtual destructor. At the end of the day it's all about communicating design.

Re:Pure virtual destructors in C++ by _stephan on Sunday November 14, 2010 @03:01PM (#1903998)
What about making the constructors protected?
Re:Pure virtual destructors in C++ by meastham on Sunday November 14, 2010 @02:24PM (#1903911)
I didn't know you could define member functions that were declared pure virtual. The more you know..