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 4249572
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:24:53+00:00 2026-05-21T04:24:53+00:00

I have the following variable that I need to work with, and have to

  • 0

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:

What I have:

From given header for library:

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;

My class (of course included in header):

pixels& MyWrapper::operator[] (const int nIndex) {
    return Image.pixels[nIndex]; // where Image is of type image
}

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

  • 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-05-21T04:24:54+00:00Added an answer on May 21, 2026 at 4:24 am

    It’s not clear why you are using double indirection in the first place.

    If pixels is a double pointer to an array of pixels, you can do

    pixels& MyWrapper::operator[] (const int nIndex) {
        return (*Image.pixels)[nIndex]; // where Image is of type image
    }
    

    If pixels is a pointer to an array of pointers to arrays, then you need two indices:

    pixels& MyWrapper::operator() ( int xIndex, int yIndex ) {
        return Image.pixels[yIndex][xIndex]; // where Image is of type image
    }
    

    There are a few weird things going on here.

    • typedef class { } identifier is not good C++. Use class identifier { };, or else the class has no name, so you cannot define member functions outside the class { } scope. (Among other problems.)
    • There is no reason to make a parameter type const int. Plain int accomplishes the same thing.
    • There is no apparent reason for the double indirection. Typically in C++ we avoid the direct use of pointers. There is probably a prepackaged standard structure you can use instead.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following variable that accepts a file name: var xtr = new
I have the following function, which I use (admitedly, as a hack, since I
So I have a class that has the following member variables. I have get
I have the following table variable in SQL Server 2005: DECLARE @results TABLE (id
If I have the following nvarchar variable - BTA200, how can I extract just
Let's say I have the following simple table variable: declare @databases table ( DatabaseID
Alright, I have been doing the following (variable names have been changed): FileInputStream fis
I have the following code to set a userId variable: (userId set in prior
I have the following string in a variable. Stack Overflow is as frictionless and
I have the following string in the smarty (php templating system) variable $test: <img

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.