Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9039491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:44:36+00:00 2026-06-16T09:44:36+00:00

I have an awkward question. I think it’s impossible but I need to know

  • 0

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.

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.

class Image
{
    private:
        std::vector<RGB> Pixels;
};



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


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

Such that when I do:

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.
}

Currently my classes look like:

class Bitmap
{
    private:
        std::vector<RGB> Pixels;

    public:
        Bitmap();
        std::vector<RGB> GetPixels() {return Pixels;}
        void SetPixels(std::vector<RGB> Pixels) {this->Pixels = Pixels;}
};

class Png
{
    private:
        std::vector<RGB> Pixels;

    public:
        Png();
        std::vector<RGB> GetPixels() {return Pixels;}
        void SetPixels(std::vector<RGB> Pixels) {this->Pixels = Pixels;}
};

And to convert from one to the other, I have to do:

int main()
{
    Bitmap Bmp();
    Png PNG();

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

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.

I guess I’m trying to be able to do: PNG.SaveAsBitmap(…); Or BMP.SaveAsPNG(…); without creating a new instance of the other.

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T09:44:37+00:00Added an answer on June 16, 2026 at 9:44 am

    I may be oversimplyfying this. How are you loading your data? If it is the same for each image type could you have a load in the image class and just overload the Translation functions. I am not an expert on image data but could you do something similiar to:

       public Image
        {
           private Pixels data;
           public void GetPixels();
           public virtual Pixels ToFormat(FormatEnum format);
        }
    
        public Bitmap:Image
        {
            public override Pixels ToFormat(FormatEnum format)
            {
                switch(format){  
                    case FormatEnum.Bitmap:return data;break;
                    case FormatEnum.Png:return doSomethingElse();break;
                }
            }
        } 
    
       int main()
       {
          Image Img();
    
          Img.GetPixels();
    
           Bitmap Foo = Img.ToFormat(Format.BitMap);
           Png Moo = Img.ToFormat(Format.Png);
    
       }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a little bit of an awkward question, and possibly off-topic, but it
The question I have is a bit abstract, but I'll attempt to be clear
I have a very strange problem,I don't know whether it is awkward to normal
I have this very awkward question... void changeString(String str){ str = Hello world: }
I have an awkward question, it is possible to use one admin panel for
Sorry for the awkward question, I wasn't sure how to phrase it. What I
This question is a bit awkward. Is it possible to transfer the touch focus
Similar to this question , but I have one master report which contains many
I have a question similar to this but in the context of L2S. I
The phrasing in the title is awkward I know. But here goes the free

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.