24-Abstract - class Abstract cfw_ private: int data; int...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
class Abstract { private: int data; int stuff; public: Abstract(int d = 0) { stuff = data = d; } virtual void AbstractFunction() = 0; // by setting a virtual function = 0; // we are essentially setting it to null // indicating that there is no function // definition // This is a pure virtual function. }; #include <iostream> using namespace std; class DerivedAbstract : public Abstract { private: public: void AbstractFunction() { cout << "DerivedAbstract::AbstractFunction()\n"; } }; class AnotherAbstract { private: int data; int stuff; public: virtual void AbstractFunction() = 0; }; class AnotherDerivedAbstract : public AnotherAbstract { private: public: void AbstractFunction() { cout << "DerivedAbstract::AbstractFunction()\n"; // // If for some reason, we still want to define a function // body in the abstract class, we still can as you can // see below. However, this isn't the typical usage // for polymorphic behavior AnotherAbstract::AbstractFunction(); } }; // Check out the nice definition for our virtual function void AnotherAbstract::AbstractFunction() { cout << "Abstract::AbstractFunction()\n"; } // EXAMPLE class Shape {
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
protected: float length, width;
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

24-Abstract - class Abstract cfw_ private: int data; int...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online