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

The Archive Base Latest Questions

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

I’m new to C++, and I have a question that should be easy, but

  • 0

I’m new to C++, and I have a question that should be easy, but it’s making me crazy. I’m trying to set up a 2D array. The array is declared in Solver.h like so:

 protected:
    static const int gridSize = 9;
    int theGrid[gridSize][gridSize]
    int *boxes[gridSize][gridSize];
...

and I’m trying to initialize it in Solver::Solver() like so:

boxes[0] ={ &theGrid[0][0],&theGrid[0][1],&theGrid[0][2],
            &theGrid[1][0],&theGrid[1][1],&theGrid[1][2],
            &theGrid[2][0],&theGrid[2][1],&theGrid[2][2] 
          };
...

But the error I’m getting says “expression must be a modifiable lvalue” and “error: expected an expression”. This didn’t make sense to me, because I was under the impression that boxes[0] was a modifiable lvalue.

So I wrote a tiny little (non OOP) program that just has the following in it’s main():

int test[2][2];
test[0]= {1,2};
cout<<test[0][1];   //outputs "2" as expected.

And now I’m stuck and confused. What is wrong with my assignment routine in the Solver class?

To answer some questions:

I do want a multidimensional array, because eventually I’ll be setting up boxes[1] with another array of pointers to another set of data inside the theGrid, a third set in boxes[2] and so on. The idea is to take a 9×9 grid and split it into 3×3 squares (sound familiar? “Solver” should solve sudoku sets simply.) so I can check (and modify) all the values in those 3×3 squares independently.
I’m trying to get this working in VS2010.
I’m sure there’s a good algorithm to define which array members are part of each 3×3 “box” based on that boxes number but I haven’t hit it yet, and it seems less wasteful to code it once than to have the program re-create those boxes in loops every time it checks an answer. For the scope of this program the size of theGrid is inalterable, so my conscience will let me get away with a little hard coding.

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

    The problem is that { ... } is not an expression, it is an initializer. Some compilers have an extension to allow expressions to be formed using {}, and C++0x adds several new meanings to the braces, but I’m going to keep this to standard C++.

    I think the best general solution is to code a loop. You don’t really want to write all that redundancy out, right?

    Solver::Solver() {
        for ( int boxnum = 0; boxnum < 9; ++ boxnum ) {
            for ( int cellnum = 0; cellnum < 9; ++ cellnum ) {
                boxes[ boxnum ][ cellnum ]
                    = &grid[ boxnum/3*3 + cellnum/3 ][ boxnum%3*3 + cellnum%3 ];
            }
        }
    }
    

    Checked code… I believe this is the pattern you’re going for.

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

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a small JavaScript validation script that validates inputs based on Regex. I
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have an array which has BIG numbers and small numbers in it. I
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to create an if statement in PHP that prevents a single post
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.