PageRenderTime 26ms CodeModel.GetById 21ms app.highlight 4ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/rel-1-3-15/SWIG/Examples/pike/class/example.cxx

#
C++ | 48 lines | 26 code | 11 blank | 11 comment | 0 complexity | b071a78c88a0572d3538a547342d47cd MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
 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
10int Shape::nshapes = 0;
11
12// Constructor
13Shape::Shape() {
14  // printf("Shape::Shape(), this = 0x%08x\n", this);
15  nshapes++;
16}
17
18// Move the shape to a new location
19void Shape::move(double dx, double dy) {
20  x += dx;
21  y += dy;
22}
23
24// Destructor
25Shape::~Shape() {
26  // printf("Shape::~Shape(), this = 0x%08x\n", this);
27  nshapes--;
28}
29
30// Circle area
31double Circle::area() {
32  return M_PI*radius*radius;
33}
34
35// Circle perimeter
36double Circle::perimeter() {
37  return 2*M_PI*radius;
38}
39
40// Square area
41double Square::area() {
42  return width*width;
43}
44
45// Square perimeter
46double Square::perimeter() {
47  return 4*width;
48}