文档介绍:Chapter 8 Inheritance
§ Concept of Inheritance
§ Access Control
§ Inheritance Forms and Virtual Base
§ Constructors in Derived Classes
*
class Rectangle{
private:
int numVertices;
float *xCoord, *yCoord;
public:
void set(float *x, float *y, int nV);
float area();
};
Rectangle
Triangle
Polygon
class Polygon{
private:
int numVertices;
float *xCoord, *yCoord;
public:
void set(float *x, float *y, int nV);
};
class Triangle{
private:
int numVertices;
float *xCoord, *yCoord;
public:
void set(float *x, float *y, int nV);
float area();
};
§ Concept of Inheritance
*
class Rectangle{
private:
int numVertices;
float *xCoord, *yCoord;
public:
void set(float *x, float *y, int nV);
float area();
};
Rectangle
Triangle
Polygon
class Polygon{
private:
int numVertices;
float *xCoord, *yCoord;
public:
void set(float *x, float *y, int nV);
};
Concept of Inheritance
class Rectangle : public Polygon{
public:
float area();
};
*
Rectangle
Triangle
Polygon
class Polygon{
private:
int numVertices;
float *xCoord, *yCoord;
public:
void set(float *x, float *y, int nV);
};
Concept of Inheritance
class Triangle{
protected:
int numVertices;
float *xCoord, float *yCoord;
public:
void set(float *x, float *y, int nV);
float area();
};
class Triangle : public Polygon{
public:
float area();
};
*
Rectangle
Triangle
Polygon
class Polygon{
private:
int numVertices;
float *xCoord, *yCoord;
public:
void set(float *x, float *y, int nV);
};
Concept of Inheritance
class Triangle : public Polygon{
public:
float area();
};
class Rectangle : public Polygon{
public:
float area();
};
*
Concept of Inheritance
A mechanism of C++ for
Building a new class from exis