Debian Codegraph @

gcc/testsuite/g++.old-deja/g++.pt/tiemann2.C

raw
1 // { dg-do run }
2 extern "C" int printf (const char *, ...);
3 template <class T> T max (const T&x, const T&y)
4 {
5 return (x>y)?x:y;
6 }
7
8 class complex
9 {
10 double re, im;
11 public:
12 complex (double r, double i=0) { re = r; im = i; }
13 friend int operator > (const complex& x, const complex &y);
14 void print () { printf ("re = %g; im = %g;\n", re, im); }
15 };
16 int operator >(const complex& x, const complex &y)
17 {
18 double c1 = x.re * x.re + x.im * x.im;
19 double c2 = y.re * y.re + y.im * y.im;
20 return c1 > c2;
21 }
22
23 int main ()
24 {
25 complex c1 (1, 0);
26 complex c2 (2, 0);
27 complex c3 (2, 3);
28 complex c4 (2, 1);
29
30 complex m1 = max (c1, c2);
31 complex m2 = max (c3, c4);
32 m1.print ();
33 m2.print ();
34 return 0;
35 }