如下圖,先建好文件, 這裡用的是Visual studio 2010

當然也可以用eclipse for cpp,如下圖:

AbstractShape.h
ABSTRACTSHAPE_H_
AbstractShape(
calcArea()= /* ABSTRACTSHAPE_H_ */
AbstractShape.cpp
#include ->edge = ->
Triangle.h
#include TRIANGLE_H_
Triangle:
Triangle( bottom,
/* TRIANGLE_H_ */
Triangle.cpp
#include bottom, ->bottom =->height = ->bottom * ->height /
Rectangle.h
#include RECTANGLE_H_
Rectangle:
Rectangle( bottom,
/* RECTANGLE_H_ */
Rectangle.cpp
#include bottom, ->bottom =->height = ->bottom * ->
Main.cpp
#include <iostream> = Triangle(, << triangle.getEdge() <<<< triangle.calcArea() <<= Rectangle(, << rectangle.getEdge() <<<< rectangle.calcArea() <<
編譯運行,運行結果: