Debian Codegraph @

gcc/testsuite/g++.old-deja/g++.other/unchanging1.C

raw
1 // { dg-do run }
2 // { dg-options "-O2" }
3 // { dg-skip-if "requires hosted libstdc++ for iostream" { ! hostedlib } }
4
5 #include <iostream>
6 #include <complex>
7
8 using namespace std;
9
10 class A {
11 protected:
12 int a;
13 complex<double> *b;
14 public:
15 A(int n);
16 inline complex<double>& operator[] (int x);
17 };
18
19 A::A(int n)
20 {
21 a = n;
22 b = new complex<double>[a];
23 for (int i=0; i<a; i++) b[i] = complex<double>(0.0,0.0);
24 }
25
26 inline complex<double>& A::operator[](int x)
27 {
28 if (x < 0 || x >= a)
29 cout << "x error" << endl;
30 return b[x];
31 }
32
33 void foo ()
34 {
35 int n = 5;
36 A *o = new A(n);
37 A *p = new A(n);
38 for (int i = 0; i < n; i++) {
39 cout << i << endl;
40 (*o)[i] *= complex<double>((*p)[i].real(), (*p)[i].imag());
41 }
42 }
43
44 int main()
45 {
46 foo();
47 }