title: Iterate through array of objects in C++
body: <p>I'm trying to iterate through <code>ArrayPlayers</code> to find the oldest player. The logic would be to have a final pointer <code>Player *Oldest</code> to the oldest player. Here is my code:</p>
  
  <pre class="lang-cs prettyprint-override"><code>#include &lt;stdio.h&gt;
  #include &lt;tchar.h&gt;
  #include &lt;iostream&gt;
  using namespace std;
  
  class Player {
      int Age;
      char *Name;
  public:
      Player() {}
  
      void setName(char *n) {
          Name = n;
      }
  
      void setAge(int a) {
          Age = a;
      }
  
      bool operator &gt; (Player &amp;P) {
          return Age &gt; P.Age;
      }
  };
  
  int main()
  {
      int NumPlayers;
  
      cout &lt;&lt; "How many persons do you want to enter?\n";
      cin &gt;&gt; NumPlayers;
  
      Player *ArrayPlayers = new Player[NumPlayers];
  
      int age;
      char *name = new char;
      for (int i = 0; i &lt; NumPlayers; i++) {
          cout &lt;&lt; "Enter player name: ";
          cin &gt;&gt; name;
          cout &lt;&lt; "Enter player age: ";
          cin &gt;&gt; age;
          ArrayPlayers[i].setName(name);
          ArrayPlayers[i].setAge(age);
      }
  
      //Find oldest player
      Player *Current = ArrayPlayers[0];
      Player *Previous = NULL;
      Player *Oldest = NULL;
      while (Current) {
          if (!Previous) {
              Oldest = Current;
              Current = Current + 1;
          } else {
              //Make comparison using overloading operator &gt;
              if (Current &gt; Oldest) { 
                  Oldest = Current;
                  Current = Current + 1;
              }
          }
      }
  
      return 0;
  }
  </code></pre>
  
  <p>What happens is that the following instruction is not permitted:</p>
  
  <pre><code>Player *Current = ArrayPlayers[0];
  
  error C2440: 'initializing' : cannot convert from 'Player' to 'Player *'
  </code></pre>
  
  <p>Basically here I wanted to set a pointer to the first element of the array. </p>
  
  <p>Can you point the reason for this error please? Do you see any other issues?</p>
  
  <p>Thanks for your help.</p>