title: Cannot convert type to type* - C++ compile error
body: <p>I am trying to create a dynamic array of type 'T' that contains an array of type 'X'. In order to access attributes of T from X, I tried creating a pointer in struct X that points to T. This is the code I have:</p>
  
  <pre><code>struct WireSeg; // Forward declaration
  
  struct Track { // Type X in above description
      int trackNum;
      bool used;
      WireSeg* parentWireSeg;
  };
  
  struct WireSeg { // Type T in above description
      int xCoord; 
      int yCoord;
      char flag;
      char orientation;
      Track* track;
  };
  
  typedef WireSeg* WireSegPtr
  
  int main (void) {
    WireSegPtr wireSeg;
    wireSeg = new WireSeg[5];
    for (int i =0; i&lt;5; i++) {
      wireSeg[i].track = new Track[3];
      for (int j =0; j&lt;3; j++) {
        wireSeg[i].track[j].parentWireSeg = wireSeg[i];
      }
    }
  }
  </code></pre>
  
  <p>I get the compile error:</p>
  
  <blockquote>
    <p>error: cannot convert ‘WireSeg’ to ‘WireSeg*’ in assignment</p>
  </blockquote>
  
  <p>I don't get it. <code>parentWireSeg</code> has been declared as a <code>WireSeg</code> type pointer and <code>wireSeg[i]</code> is also an element in the <code>wireSeg</code> array and is a pointer (isn't it?).</p>
  
  <p>I tried playing around with it and declared <code>parentWireSeg</code> to be of type <code>WireSeg</code>:</p>
  
  <pre><code>struct Track {
      int trackNum;
      bool used;
      bool flag;
      WireSeg parentWireSeg;
  };
  </code></pre>
  
  <p>This gave me error: </p>
  
  <blockquote>
    <p>‘struct Track’ has no member named ‘parentWireSeg’.</p>
  </blockquote>
  
  <p>This makes no sense to me either since struct <code>Track</code> does have <code>parentWireSeg</code> as an element! Can someone please explain this? Am I not allowed to have a pointer in <code>Track</code> that points to <code>WireSeg</code>?</p>
  
  <p>I can probably use inherited classes (can I?) for this but I would prefer if someone told me what is wrong with my method?</p>