--- /dev/null
+cdef extern from "shapes.h" namespace shapes:
+
+ cdef cppclass Shape:
+ area()
+
+ cdef cppclass Rectangle(Shape):
+ int width
+ int height
+ __init__(int, int)
+
+ cdef cppclass Square(Shape):
+ int side
+ __init__(int)
+
+cdef Rectangle *rect = new Rectangle(10, 20)
+cdef Square *sqr = new Square(15)
+
+del rect, sqr
--- /dev/null
+#include "shapes.h"
+
+using namespace shapes;
+
+Rectangle::Rectangle(int width, int height)
+{
+ this->width = width;
+ this->height = height;
+}
+
+Square::Square(int side)
+{
+ this->side = side;
+}
+
--- /dev/null
+#ifndef SHAPES_H
+#define SHAPES_H
+
+namespace shapes {
+
+ class Shape
+ {
+ public:
+ virtual float area() = 0;
+ virtual ~Shape() { }
+ };
+
+ class Rectangle : public Shape
+ {
+ public:
+ Rectangle(int width, int height);
+ float area() { return width * height; }
+ int width;
+ int height;
+ };
+
+ class Square : public Shape
+ {
+ public:
+ Square(int side);
+ float area() { return side * side; }
+ int side;
+ };
+
+}
+#endif