I want to preface this by saying that the MS compiler team have worked wonders in improving developer productivity over the years, and can’t be thanked enough for turning the C++ language into an enterprise quality platform that has lasted more than a decade.
That said, “C2259: ‘CFoo’ : cannot instantiate abstract class” is probably one of the least useful of the compiler errors. This error occurs on a line where I am trying to instantiate a CFoo object, and the compiler has determined that CFoo is an abstract class. The problem is that most of the time CFoo isn’t supposed to be an abstract class. I’m trying to instantiate it, so chances are good that, semantically, I don’t intend CFoo to be an abstract class. The compiler, however, has determined that there is some pure virtual function that isn’t overridden, and therefore the class is abstract and cannot be instantiated.
The reason this is a problem is that, in most cases, the bug is not that I’m trying to instantiate the class. The bug is that CFoo hasn’t overridden a pure virtual function that needs to be overridden so that CFoo is not abstract. The compiler does a good job of flagging down that there’s an error, but it’s unhelpful because in most cases, it’s flagging down the wrong error.
So what? The compiler can’t be expected to discern programmer intent. That’s why programmers make the big bucks, right? Lots of error codes are cryptic so why single this one out? Because it’s fixable. It’s not an unknowable problem. It’s just an oversight is all. The answer isn’t even technically difficult from a compiler’s POV. The compiler has already determined that my class is abstract. It should be easy from there to tell me why the compiler thinks my class is abstract.
C2259: ‘CFoo’ : cannot instantiate abstract class. CFooBase::Bar(int, void*, const char*) is not overridden.