~ubuntu-branches/ubuntu/warty/swig1.3/warty

« back to all changes in this revision

Viewing changes to Examples/tcl/operator/example.h

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Landschoff
  • Date: 2002-03-29 01:56:07 UTC
  • Revision ID: james.westby@ubuntu.com-20020329015607-c0wt03xu8oy9ioj7
Tags: upstream-1.3.11
ImportĀ upstreamĀ versionĀ 1.3.11

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* File : example.h */
 
2
#include <math.h>
 
3
 
 
4
class Complex {
 
5
private:
 
6
  double rpart, ipart;
 
7
public:
 
8
  Complex(double r = 0, double i = 0) : rpart(r), ipart(i) { }
 
9
  Complex(const Complex &c) : rpart(c.rpart), ipart(c.ipart) { }
 
10
  Complex &operator=(const Complex &c) {
 
11
    rpart = c.rpart;
 
12
    ipart = c.ipart;
 
13
    return *this;
 
14
  }
 
15
  Complex operator+(const Complex &c) const {
 
16
    return Complex(rpart+c.rpart, ipart+c.ipart);
 
17
  }
 
18
  Complex operator-(const Complex &c) const {
 
19
    return Complex(rpart-c.rpart, ipart-c.ipart);
 
20
  }
 
21
  Complex operator*(const Complex &c) const {
 
22
    return Complex(rpart*c.rpart - ipart*c.ipart,
 
23
                   rpart*c.ipart + c.rpart*ipart);
 
24
  }
 
25
  Complex operator-() const {
 
26
    return Complex(-rpart, -ipart);
 
27
  }
 
28
  
 
29
  double re() const { return rpart; }
 
30
  double im() const { return ipart; }
 
31
};
 
32
 
 
33
 
 
34
 
 
35
 
 
36