Possible Duplicate:
What is the difference between a concrete class and an abstract class?
I was coding something in Visual C++ 2008 doing an exercise in a book I am reading when I held my cursor over one of the classes and it told me it was an abstract class. Now I know it is an abstract class as that is what this exercise is about but I was curious as to what lets the Intelisense thing know that it is an abstract class.
I did a little homework and found that it may have been the fact that I have two virtual functions in this class and one of them is a pure virtual.
Is the pure virtual a dead giveaway or are there other things that would tell you you are dealing with or looking at an abstract class?
In C++, yes. Since it has no
abstractkeyword or equivalent, the common idiom to make a class abstract is to declare a pure virtual function in it (which prevents instantiation).*For this same reason, in C++ there is not much difference between an interface and an abstract class – a C++ interface is simply a class containing only pure virtual functions.
*Update: Another way to prevent instantiation of a class is to declare its constructor(s)
protectedorprivate. The latter means it can’t be subclassed either, but the former doesn’t prevent subclassing, so in theory a protected constructor could also bea sign of an abstract classa way to force subclassing. However, I have never seen this in practice. I believe this is because an abstract class is designed to be extended, which in practice almost always means it has virtual functions. And the reason why we want it to be abstract is because some part of its implementation is not yet known, hence it is to be defined in its subclass(es). Which is exactly what a pure virtual function is meant for.