In C++, it is legal to give an implementation of a pure virtual function:
class C
{
public:
virtual int f() = 0;
};
int C::f()
{
return 0;
}
Why would you ever want to do this?
Related question: The C++ faq lite contains an example:
class Funct {
public:
virtual int doit(int x) = 0;
virtual ~Funct() = 0;
};
inline Funct::~Funct() { } // defined even though it's pure virtual; it's faster this way; trust me
I don't understand why the destructor is declared pure virtual and then implemented; and I don't understand the comment why this should be faster.