/trunk/Examples/ruby/reference/example.cxx
C++ | 46 lines | 35 code | 9 blank | 2 comment | 3 complexity | 2fb046e512cf8c73b15e5c64d25c5f3d MD5 | raw file
1/* File : example.cxx */ 2 3/* Deal with Microsoft's attempt at deprecating C standard runtime functions */ 4#if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) 5# define _CRT_SECURE_NO_DEPRECATE 6#endif 7 8#include "example.h" 9#include <stdio.h> 10#include <stdlib.h> 11 12Vector operator+(const Vector &a, const Vector &b) { 13 Vector r; 14 r.x = a.x + b.x; 15 r.y = a.y + b.y; 16 r.z = a.z + b.z; 17 return r; 18} 19 20char *Vector::print() { 21 static char temp[512]; 22 sprintf(temp,"Vector %p (%g,%g,%g)", this, x,y,z); 23 return temp; 24} 25 26VectorArray::VectorArray(int size) { 27 items = new Vector[size]; 28 maxsize = size; 29} 30 31VectorArray::~VectorArray() { 32 delete [] items; 33} 34 35Vector &VectorArray::operator[](int index) { 36 if ((index < 0) || (index >= maxsize)) { 37 printf("Panic! Array index out of bounds.\n"); 38 exit(1); 39 } 40 return items[index]; 41} 42 43int VectorArray::size() { 44 return maxsize; 45} 46