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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:31:48+00:00 2026-06-10T04:31:48+00:00

I’m a beginning programmer and I’ve been having quite a bit of trouble with

  • 0

I’m a beginning programmer and I’ve been having quite a bit of trouble with C++ OOP. Specifically, tonight I was trying to write a simple class that takes in events and switches between multiple images, with a pointer to each image stored in an array. I ran into a confusing problem when trying to make a ‘getter’ function that returns a pointer to the array itself.

Basically, I was trying to do something like this:

class SlideShow
{
public:
    image *getSlideArray();
private:
    image *slideArray[10];
};

So, I wanted to have an array that stores pointers to each image. And I also wanted to have a function that returns the address of the array itself. I ran into an issue when trying to define the getSlideArray() function… I’m just not entirely sure why it wasn’t working…

Here’s what I tried initially, in my class’ source file:

image *SlideShow::getSlideArray()
{
    return this->slideArray;
}

In this attempt, the compiler kept raising issues with the use of the ‘this’ keyword, saying that what I was trying to return was not of the previously specified type. However, this is the way that I’ve been writing my getter functions up until now, and it generally works when using simple variables… My suspicion is that there is some problem here due to the fact that ‘this’ is a pointer, and ‘slideArray’ is a pointer to an array that also contains pointers… But I’m terrible and that level of referencing kind of goes over my head right now. It’s been taking me a while just to gather a basic understanding of pointers, referencing using address & operator, etc. Pointers to pointers and arrays of pointers are even more confusing.

I should also mention that I found one work around, in which my code compiles. (Although I can’t really run it to check and see if it works at runtime yet..) My work around involved adding the definition/return statement to the class declaration itself (inside the header file):

class SlideShow
{
public:
    image *getSlideArray() {return *slideArray;);
private:
    image *slideArray[10];
};

Now. This compiled correctly… BUT, it’s also confusing to me. I know that generally, when you return an array (say, an array of ints), you are returning the address of the zeroth slot of the array. But if I was trying to return an intArray[5], when returning it, I would simply write ‘intArray’, correct? Essentially, I’m not confused as to why I have to add the * before ‘slideArray’ in this situation…

So no matter which way I try and do it, it’s confusing me. I know that there is some ‘trick’ here, and that it probably has to do with returning pointers to pointers to pointers or something, but I just haven’t been able to work it out myself. I really am hoping to learn this subject so that I can start to get a handle on programming, especially OOP…

Can anyone help me understand this better?

  • 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-10T04:31:49+00:00Added an answer on June 10, 2026 at 4:31 am

    The method definition that you are using:

    image *SlideShow::getSlideArray() {
        return this->slideArray;
    }
    

    states that a pointer to an image is being returned. However, you are trying to return an array of image. You should either do:

    image *SlideShow::getSlideArray(int image_idx) {
        return this->slideArray[image_idx];
    }
    

    or

    image **SlideShow::getSlideArray() {
        return this->slideArray;
    }
    

    depending on whether you want to return all the images together (second option) or one by one (first option).

    BTW, you do not need to use this at all. The next code is equivalent to the second option above:

    image **SlideShow::getSlideArray() {
        return slideArray;
    }
    

    The previous explanation should fix your issues. However, instead of using “raw pointers” and C-style arrays, you better to use STL containers (see @juanchopanza answer for that).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am doing a simple coin flipping experiment for class that involves flipping a
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Specifically, suppose I start with the string string =hello \'i am \' me And
I am trying to render a haml file in a javascript response like so:

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.