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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:52:55+00:00 2026-06-03T05:52:55+00:00

I have a class with a 2D array of ints implemented as an int**.

  • 0

I have a class with a 2D array of ints implemented as an int**. I implemented an accessor function to this 2D array as follows, returning a const int** to prevent the user from being able to edit it:

const int** Class::Access() const
{
     return pp_array;
}

But I got the compilation error “invalid conversion from int** to const int**”. Why is a promotion to const not allowed here? How can I give the user access to the information without editing rights?

  • 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-03T05:52:56+00:00Added an answer on June 3, 2026 at 5:52 am

    I was mistaken about the constness of the method being the reason for the error. As Ben points out, the const-ness of the method is irrelavent, since that applies only to the value of the exterior pointer [to pointers to ints], which can be copied to a mutable version trivially.

    In order to protect the data (which is your preferred outcome) you should make both the ints and the pointers to ints constant:

    int const * const * Class::Access() const
    {
       return pp_array;
    }
    

    Will work.

    If you prefer to have the const in front you can also write the declaration like so:

    const int * const * Class::Access() const;
    

    but since the second const applies to the pointers, it must be placed to the right (like the const which applies to the method) of the asterisk.

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

Sidebar

Related Questions

I have a variable declared like this in a class: Entity *array[BOARD_SIZE][BOARD_SIZE]; I need
Does Scala have a version of Rubys' each_slice from the Array class?
Say I have a class with a private dispatch table. $this->dispatch = array( 1
i do this in the education purpose. such is idea: i have class Array.
I have: class first{ private: int *array; public: first(int x){ array = new int[x][10];
so I have this class in the header class C{ int b [2]; init();
i have class class Form { public function addTextarea(array $par){ $element='. $par['label'] .'; $element
I have the following code: class Array { public: int aaa; Array():aaa(1){} void print()
Let's say I have a function called MyFunction(int myArray[][]) that does some array manipulations.
I have a base class object array into which I have typecasted many different

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.