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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:23:58+00:00 2026-05-17T15:23:58+00:00

I have a static const array class member (const pointers to SDL_Surfaces, but that’s

  • 0

I have a static const array class member (const pointers to SDL_Surfaces, but that’s irrelevant), and have to loop through it in order to populate it. Aside from a const_cast when I’m done looping, which I hear is bad practice, how would I go about doing this?

EDIT:
The reason I don’t just do…

static SDL_Surface *const myArray[3];
...
class::myArray[3] = {...};

is that I need to read from a different array and run a function on the different array’s respective value in order to get the value for this array. Once I’ve looped all the way through, I’m never changing this array again, so the way I see it, it should be const.

EDIT 2:
I think I might have made a conceptual mistake here. Is it possible to const_cast in some way to make something const, instead of to remove it’s constness, which is what I was trying to do? If not, then I was being a little silly asking this 😀

  • 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-17T15:23:58+00:00Added an answer on May 17, 2026 at 3:23 pm

    One method to provide “logical constness” is to make the data inaccessible, except by non-mutating means.

    For example:

    class foo
    {
    public:
        const bar& get_bar() { return theBar; }
    
    private:
        static bar theBar;
    };
    

    Even though theBar isn’t constant, since foo is the only thing that can modify it, as long as it does so correctly you essentially (logically) have a constant bar.

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

Sidebar

Related Questions

I have a three dimensional static const array that is acting as a lookup
I have a static class that I would like to raise an event as
We have a static method in a utility class that will download a file
I have the following array declared inside a header file. static const float elementsArray[300]
Say I have the following code snippet in c# static const bool DO_PERFORMANCE_CODE =
I have several service classes that have static methods and offer a service to
I got a Utility module since VB.NET doesn't have static class like C# and
I have some static images in a folder on my IIS 6-based website that
Let's say I have a function called MyFunction(int myArray[][]) that does some array manipulations.
I have a header file for a game that declares a two-dimensional array for

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.