title: Dynamically allocated array in a class
body: <p>Here is a class, which is basically an array of numbers on which I want to perform some operations.</p>
  
  <pre><code>class MyClass {
  public:
      MyClass() { //constructor
          int * array = new int[n];
          for(int i = 0; i &lt; n; i++) {
              array[i] = i*i;
          }
      } //end constructor
      int displayIthElement(int i) {
          return array[i];
      }
  }
  </code></pre>
  
  <p>I get: error, identifier "array" is undefined in the displayIthElement function. It's as if the array array stops existing outside of the constructor function, which makes no sense. What is the problem?</p>
  
  <p>Thank you very much.</p>