Changing the stride of a pointer increment
<p>I currently have a class like this:</p>

<pre><code>struct Rgb
{
  static const int NUM_CHANNELS = 3;
  unsigned char channel[NUM_CHANNELS];
};
</code></pre>

<p>which is never instantiated but is used to determine the stride of a pointer increment.</p>

<p>I wanted to allow this stride to change based on some runtime information. Will something like this work?</p>

<pre><code>#include &lt;iostream&gt;

class Rgb
{
public:
  static int* Channel;
  static void SetChannelSize(unsigned int channelSize)
  {
    Channel = new int(channelSize);
  }
};

int main()
{

  int numbers[1000];
  for(unsigned int i = 0; i &lt; 1000; i++)
    {
    numbers[i] = i;
    }

  Rgb::SetChannelSize(3);

  Rgb* rgbNnumbers = reinterpret_cast&lt;Rgb*&gt;(numbers);

  for(unsigned int i = 0; i &lt; 5; i++)
    {
    std::cout &lt;&lt; rgbNnumbers[i] &lt;&lt; std::endl; //error: no match for ‘operator&lt;&lt;’ in ‘std::cout &lt;&lt; *(rgbNnumbers + ((unsigned int)i))’

    }

  return 0;
}
</code></pre>

<p>(I wasn't sure how to step over the demo array I setup in this example to test it out).</p>

<p>Any comments?</p>

<p>Thanks,</p>

<p>David</p>
