title: Dynamically allocating array of objects
body: <p>I need a double pointer of type DizzyCreature (my class) to point to an array of DizzyCreature pointers.  When I run it I get "Access violation reading location 0x...".  I can make a DizzyCreature* and call its member functions just fine, but when cannot run through the array and do the same thing for each obj.</p>
  
  <p>I am following these instructions:
  <a href="http://www.cplusplus.com/forum/beginner/10377/" rel="nofollow">http://www.cplusplus.com/forum/beginner/10377/</a></p>
  
  <p>Code</p>
  
  <p>Server.h:</p>
  
  <pre><code>class Server
  {
   public:
    Server(int x, int y, int count);
    ~Server(void);
  
    void tick();
  
  
   private:
    DizzyCreature** dcArrPtr;
    DizzyCreature* dcPtr;
  
    int _count;
  };
  </code></pre>
  
  <p>Server.cpp:</p>
  
  <pre><code>Server::Server(int x, int y, int count)
  {
    dcPtr = new DizzyCreature[count];       // this works just fine
  
    dcArrPtr = new DizzyCreature*[count];   // this doesn't (but gets past this line)
    _count = count;
  }
  
  Server::~Server(void)
  {
    delete[] *dcArrPtr;
    delete[] dcPtr;
  }
  
  void Server::tick()
  {
    dcPtr-&gt;takeTurn();                // just fine
  
    for (int i = 0; i &lt; _count; i++) {
      dcArrPtr[i]-&gt;takeTurn();        // crash and burn
    }
  }
  </code></pre>
  
  <p>EDIT:
  The member function takeTurn() is in a parent class of DizzyCreature.  The program makes it into the function, but as soon as it attempts to change a private member variable the exception is thrown.  If it matters, DizzyCreature is of type GameCreature and WhirlyB as this is an assignment on MI.</p>