import source from 1.3.40
[external/swig.git] / Examples / pike / class / example.cxx
1 /* File : example.c */
2
3 #include "example.h"
4
5 #include <stdio.h>
6
7 #define M_PI 3.14159265358979323846
8
9 // Static member initializer
10 int Shape::nshapes = 0;
11
12 // Constructor
13 Shape::Shape() {
14   nshapes++;
15 }
16
17 // Move the shape to a new location
18 void Shape::move(double dx, double dy) {
19   x += dx;
20   y += dy;
21 }
22
23 // Destructor
24 Shape::~Shape() {
25   nshapes--;
26 }
27
28 // Circle area
29 double Circle::area() const {
30   return M_PI*radius*radius;
31 }
32
33 // Circle perimeter
34 double Circle::perimeter() const {
35   return 2*M_PI*radius;
36 }
37
38 // Square area
39 double Square::area() const {
40   return width*width;
41 }
42
43 // Square perimeter
44 double Square::perimeter() const {
45   return 4*width;
46 }