Search code examples
c++language-lawyerabstract-classvirtual-functionspure-virtual

Have pure virtual methods always existed in C++?


I found some code in a work project that throws errors when a child class has not overridden a base class function (essentially, base classes that use this utility are effectively abstract). When I saw this, my first reaction was, "Why don't they just make those methods pure virtual?" However, the code in question is ~15 years old and I wasn't certain whether or not it was created to fill the gap that pure virtual would fill later (assuming it didn't exist at the time).

  • If pure virtual methods have existed since then, is there any reason to provide them additional or alternative functionality? (I realize this may be subjective, but I don't even have a starting point here).

  • If they haven't, is there any documentation that points to which standard introduced them?


Solution

  • Pure virtual functions have (always) existed since the first official C++98 standard (and likely earlier).

    Refer to ISO/IEC 14882:1998 [class.abstract]

    A class is abstract if it has at least one pure virtual function.

    Doing some more digging, in Stroustrup's "A History of C++: 1979− 1991" (pdf), he mentions abstract classes made an appearance around 1989. Saying

    "The very last feature added to 2.0 before it shipped was abstract classes"