title: C++: Using function calling Derived class in Base class
body: <p>How do I use <code>Derived</code> class in <code>Base</code> class? </p>
  
  <p><strong>EDIT 2:</strong>
  When calling <code>virtual void move(Derived1 &amp;race);</code> in main, it doesn't compile, but throws error that <code>Derived1 is not found</code>. When I to call the function without the <code>Derived1</code> class object, it does compile, but the function doesn't seem to do anything. Is it possible to get that function to work?</p>
  
  <p><strong>EDIT :</strong></p>
  
  <p><strong>Base class</strong></p>
  
  <pre><code>class Base {
  protected:
      int x, y;
      int moves;
      char name;
      bool free;
  public:
      Base();
      virtual void move(Derived1 &amp;race);
  };
  </code></pre>
  
  <p><strong>Derived class 1</strong></p>
  
  <pre><code>class Derived1 : public Base {
  private:
      const int x = 10;
      const int y = 60;
      Base ***track;
  public:
      Derived1(int x = 10, int y = 60);
      void printBoard();
      Base ***getArray() const;
      ~Derived1();
      void move{}
  };
  </code></pre>
  
  <p><strong>Derived class 2</strong></p>
  
  <pre><code>class Derived2 : public Base {
  public:
      Derived2();
      Derived2(int x, int y);
      void move(Derived1&amp; race);
  };
  </code></pre>
  
  <p><strong>void move() function of Derived 2</strong></p>
  
  <p><em>It checks for obstacles in array. If free space is found it moves there. The code is really bad, since I haven't finished it, just a temporary code before I get everything going smoothly.</em></p>
  
  <pre><code>void Derived2::move(Derived1&amp; race) {
      if (race.getArray()[x][y + 1]-&gt;getFree() == true) {
          delete[] race.getArray()[x][y];
          race.getArray()[x][y] = new Base();
      }
      if (race.checkFreeY(x, y + 1, 3) == true) {
          delete[] race.getArray()[x][y + 4];
          race.getArray()[x][y + 4] = new Derived2(x, y + 4);
          moves++;
      }
      else if (race.checkFreeX(x, y + 1, 3) == true) {
          delete[] race.getArray()[x + 3][y + 1];
          race.getArray()[x + 3][y + 1] = new Derived2(x + 3, y + 1);
          moves++;
      }
      else {
          moves++;
      }
  }
  </code></pre>
  
  <p>The assignment was to make a race with a <code>virtual move()</code> function used in every other <strong>Derived</strong> class, that moves the object in a 2D array with obstacles.</p>
  
  <p><strong>EDIT 3:</strong></p>
  
  <p><em>The call I'm trying to make:</em></p>
  
  <pre><code>Derived1 track;
  track.fillTrack();
  track.genBushes();
  track.genRacers();
  track.getArray()[0][0]-&gt;move(track);
  </code></pre>
  
  <p>When doing this, I get following errors:</p>
  
  <pre><code>syntax error: identifier 'Derived1'
  'void Base::move(Derived1&amp;)': overloaded member function not found in 'Base'
  "void Base::move(&lt;error-type&gt; &amp;race)"
  </code></pre>
  
  <p>Editing move function in <code>Base</code> as follows <code>virtual void move() {}</code> and trying to call like <code>track.getArray()[0][0]-&gt;move();</code> I'm getting following error:</p>
  
  <p><code>too few arguments in function to call</code></p>