Hereβs some ugly syntax:
class Super { public: virtual void foo() = 0; }; int main() { Super s; s.foo(); return 0; }
c.cc:7: error: cannot declare variable 's' to be of abstract type 'Super'
Since Super
contains a pure virtual function, it cannot be
instantiated. It is an Abstract Base Class, or ABC.
Itβs similar to an interface in Java.
class Super { public: virtual void foo() = 0; }; class Sub : public Super { public: void foo() { clog << "Aquaman or the Sub-Mariner? You decide!\n" << "ππππππππππππππππππππππππ\n"; } }; int main() { Sub s; s.foo(); return 0; }
Aquaman or the Sub-Mariner? You decide! ππππππππππππππππππππππππ
Sub
has no pure virtual functions remaining, so it can be instantiated.