Child classes that share Parent class member
<p>I have an awkward question. I think it's impossible but I need to know for sure. It's a bit of an odd request, but I need my child classes to share the SAME Pixels vector from the parent class.</p>

<p>Basically, I want to create an instance of Image class. That Image class will hold Pixels for both Bitmap and Png Class so that if I need to convert from Bitmap To PNG and Vice-versa, they use the same vector rather than me creating both Bitmap and PNG classes.</p>

<pre><code>class Image
{
    private:
        std::vector&lt;RGB&gt; Pixels;
};



class Bitmap : Image
{
    public:
        Bitmap() : Image() {};
};


class Png : Image
{
    public:
        Png() : Image() {};
};
</code></pre>

<p>Such that when I do:</p>

<pre><code>int main()
{
    Image Img();

    Img.GetBitmapPixels();  //This
    Img.GetPngPixels();     //And this, return the same Pixels Vector.

    Bitmap Foo = Img.ToPng();
    Png Moo = Img.ToBitmap();
    //Such that both Foo and Moo have the exact same underlying Pixels Vector.
}
</code></pre>

<p>Currently my classes look like:</p>

<pre><code>class Bitmap
{
    private:
        std::vector&lt;RGB&gt; Pixels;

    public:
        Bitmap();
        std::vector&lt;RGB&gt; GetPixels() {return Pixels;}
        void SetPixels(std::vector&lt;RGB&gt; Pixels) {this-&gt;Pixels = Pixels;}
};

class Png
{
    private:
        std::vector&lt;RGB&gt; Pixels;

    public:
        Png();
        std::vector&lt;RGB&gt; GetPixels() {return Pixels;}
        void SetPixels(std::vector&lt;RGB&gt; Pixels) {this-&gt;Pixels = Pixels;}
};
</code></pre>

<p>And to convert from one to the other, I have to do:</p>

<pre><code>int main()
{
    Bitmap Bmp();
    Png PNG();

    PNG.SetPixels(BMP.GetPixels);   //BMP has to COPY PNG's Pixels and vice-versa..
}
</code></pre>

<p>It's kind of a stupid question. I just don't want to copy pixels. I just want to be able to convert between the two classes without any copying as both classes hold an std::vector Pixels member and the data is aligned the same.</p>

<p>I guess I'm trying to be able to do: PNG.SaveAsBitmap(...); Or BMP.SaveAsPNG(...); without creating a new instance of the other.</p>

<p>How can I avoid copying/creating and making a new instance of the other class I'm converting to? Can I have classes that inherit from eachother?</p>
