summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.old-deja/g++.other/unchanging1.C
blob: 6b2999cb95a2ff316a1b5ada6d8b5ac11c3d2193 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// { dg-do run  }
// { dg-options "-O2" }

#include <iostream>
#include <complex>

using namespace std;

class A {
protected:
  int a;
  complex<double> *b;
public:
  A(int n);
  inline complex<double>& operator[] (int x);
};

A::A(int n)
{
  a = n;
  b = new complex<double>[a];
  for (int i=0; i<a; i++) b[i] = complex<double>(0.0,0.0);
}

inline complex<double>& A::operator[](int x)
{
  if (x < 0 || x >= a)
    cout << "x error" << endl;
  return b[x];
}

void foo ()
{
  int n = 5;
  A *o = new A(n);
  A *p = new A(n);
  for (int i = 0; i < n; i++) {
    cout << i << endl;
    (*o)[i] *= complex<double>((*p)[i].real(), (*p)[i].imag());
  }
}

int main()
{
  foo();
}