PageRenderTime 40ms CodeModel.GetById 16ms 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. #include "example.h"
  3. #include <stdio.h>
  4. #define M_PI 3.14159265358979323846
  5. // Static member initializer
  6. int Shape::nshapes = 0;
  7. // Constructor
  8. Shape::Shape() {
  9. // printf("Shape::Shape(), this = 0x%08x\n", this);
  10. nshapes++;
  11. }
  12. // Move the shape to a new location
  13. void Shape::move(double dx, double dy) {
  14. x += dx;
  15. y += dy;
  16. }
  17. // Destructor
  18. Shape::~Shape() {
  19. // printf("Shape::~Shape(), this = 0x%08x\n", this);
  20. nshapes--;
  21. }
  22. // Circle area
  23. double Circle::area() {
  24. return M_PI*radius*radius;
  25. }
  26. // Circle perimeter
  27. double Circle::perimeter() {
  28. return 2*M_PI*radius;
  29. }
  30. // Square area
  31. double Square::area() {
  32. return width*width;
  33. }
  34. // Square perimeter
  35. double Square::perimeter() {
  36. return 4*width;
  37. }