Class - PowerPoint PPT Presentation

1 / 5
About This Presentation
Title:

Class

Description:

... generic sense, Shapes, there is no need to define a Shape when defining these ... The abstract class Shape has no data members, and provides no functional ... – PowerPoint PPT presentation

Number of Views:21
Avg rating:3.0/5.0
Slides: 6
Provided by: chrisf2
Category:
Tags: class | shape

less

Transcript and Presenter's Notes

Title: Class


1
  • Class 20 Abstract Classes

2
ABCs
  • Abstract Classes vs. Concrete Classes What if we
    wanted a class that never needs to instantiate an
    object?  It is possible that we would never need
    to instantiate a generic object such as a Shape. 
    Even though all Circles, Triangles, Rectangles,
    etc. are, in the most generic sense, Shapes,
    there is no need to define a Shape when defining
    these derived class objects.  In this case a
    Shape class would be an abstract class.

3
Simple Abstract Class
  • class Shape
  • public    virtual void Draw() const 0 //
    pure virtual function private

4
Abstract classes
  • The abstract class Shape has no data members, and
    provides no functional operations that aren't
    handled at the derived class level. 
  • However, if we wanted to declare a pointer to a
    concrete class object circle, triangle, or
    rectangle, we might not know in advance what the
    derived class of the object will be. 
  • Therefore, the Shape class allows us to define
    one type of pointer, a Shape pointer, and use it
    to draw whichever type of Shape is created.

5
Properties of ABCs
  • Abstract classes provide a base class from which
    classes may inherit a common interface and/or
    implementation.
  • They are too generic to define any real objects.
  • Identified by having one or more purely virtual
    member functions.
  • NOTE If a derived class (2-D Shape) has no
    definition for a pure virtual member function,
    that function remains a pure virtual function,
    and so the derived class is also an abstract
    class.
  • Attempts to define an object from abstract class
    is a syntax error.
  • Concrete classes provide the specifics to define
    each object.
Write a Comment
User Comments (0)
About PowerShow.com