title: Overloading subscript operator and working with double-pointers?
body: <p>I have the following variable that I need to work with, and have to write my own wrapper around it for an assignment. I am going beyond the assignment (since I am going to have to use this wrapper I make) and wanting to overload the subscript operator in my wrapper in order to use it with the double pointer array. What I mean in code is this:</p>
  
  <p>What I have:</p>
  
  <p>From given header for library:</p>
  
  <pre><code>typedef struct {        // A pixel stores 3 bytes of data:
      byte red;       //  intensity of the red component
      byte green;     //  intensity of the green component
      byte blue;      //  intensity of the blue component
  } pixel;
  
  typedef struct { 
      int   rows, cols;   /* pic size */
      pixel **pixels;     /* image data */
  } image;
  </code></pre>
  
  <p>My class (of course included in header):</p>
  
  <pre><code>pixels&amp; MyWrapper::operator[] (const int nIndex) {
      return Image.pixels[nIndex]; // where Image is of type image
  }
  </code></pre>
  
  <p>Of course this won't work since the double pointer returns a pointer, which is not what I'm telling it to return, yet returning *pixels&amp; doesn't return it either. Just to sate my curiosity and to help me understand why this isn't possible, could someone tell me how this would be implemented if it can be at all, and why it is that way? Keep in mind I don't understand pointers very well yet (I know of the basics of how they work, but thats it), and am hoping to use this to very much broaden my understanding.</p>