CS253 Pure Virtual
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.
Modified: 2017-02-23T16:44 User: Guest Check: HTML CSSEdit History Source |
Apply to CSU |
Contact CSU |
Disclaimer |
Equal Opportunity Colorado State University, Fort Collins, CO 80523 USA © 2015 Colorado State University |