title: error C2027: use of undefined type - how to declare class
body: <p>I am running into below error - when I just provide the definition of class first and then declare it later. My understanding was as long as we do that as I have done numerous times for function definition, compiler gets it but seems my understanding is flawed can someone help me understand what is missing part in understanding of how to declare class.</p>
  
  <pre><code>error C2027: use of undefined type 'generic_iterator'
  note: see declaration of 'generic_iterator  
  </code></pre>
  
  <p><strong>Does not work</strong> - error shown above</p>
  
  <pre><code>#include &lt;iostream&gt;
  class generic_iterator;
  class darray
  {
  public:
      typedef generic_iterator iterator;
      darray();
      darray(int size);
      ~darray();
      int&amp; at(int index);
      int&amp; operator [](int i);
      int* data(void);
      bool empty();
      void fill(int val);
      void print();
      size_t max_size();
      iterator begin() {return iterator(ptrarray); }
      iterator end() { return iterator(ptrarray + size); }
  
  private:
      int *ptrarray;
      int num_elements;
      int size;
  };
  
  class generic_iterator
  {
  public:
      generic_iterator(int *ptr);
      ~generic_iterator();
      generic_iterator&amp; operator++();     // pre-increment
      generic_iterator operator++(int);    // post-increment
  private:
      int *iptr;
  };
  </code></pre>
  
  <p><strong>Works</strong> :  When entire class is declared first</p>
  
  <pre><code>class generic_iterator
  {
  public:
      generic_iterator(int *ptr);
      ~generic_iterator();
      generic_iterator&amp; operator++();     // pre-increment
      generic_iterator operator++(int);    // post-increment
  private:
      int *iptr;
  };
  
  class darray
  {
  public:
      typedef generic_iterator iterator;
      darray();
      darray(int size);
      ~darray();
      int&amp; at(int index);
      int&amp; operator [](int i);
      int* data(void);
      bool empty();
      void fill(int val);
      void print();
      size_t max_size();
      iterator begin() {return iterator(ptrarray); }
      iterator end() { return iterator(ptrarray + size); }
  
  private:
      int *ptrarray;
      int num_elements;
      int size;
  };
  </code></pre>