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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T09:31:53+00:00 2026-06-02T09:31:53+00:00

I need a variable which will hold 22 pairs of ints (positions in a

  • 0

I need a variable which will hold 22 pairs of ints (positions in a grid) so I was thinking of having a matrix array. So in my header file is:

int points[22][2];

but when I put the following in the constructor of the object:

this->points = {{1,2},{2,3},...};

It says “must be a expression must be a modifiable lvalue” I’ve tried using the const keyword and making it a pointer in the header file as described here Expression must be a modifiable L-value

I’ve also tried creating a separate 2d array and then assigning it but this doesn’t work either.

int points2 = {{1,2},{2,3},...};
this->points = points2;

I’m used to Java and I’m not too experienced with C++. There is a default constructor that will assign the values as above and a constructor which will have the matrix as parameter.

The following does work:

this->point[1][1] = 4;

But this means I can’t pass another value as a parameter and I end up with 44 lines of messy code in the default constructor! And I was going to use a struct with 2 ints and put them in a vector put that seems like a bit of an overkill and would mean I need 22 vector inserts before I even called the constructor with the manual values and I just thought there must be a better way 🙂

Thanks

  • 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-02T09:31:55+00:00Added an answer on June 2, 2026 at 9:31 am

    Since you’re using C++, a much better choice would be to use a vector of pairs of ints.

    Declare it like this:

    std::vector<std::pair<int, int> > points;
    

    In your constructor you can specify size at initialization

    : points(22), 
    

    or set it at any point like this:

    points.resize(22);
    

    You can access individual coordinates with

    points[1].first = 1;
    points[1].second = 44;
    

    or with

    points[1] = make_pair(1, 44);
    

    or you can build it up without having to worry about exceeding its allocated size with

    points.push_back(make_pair(1, 44));
    

    etc

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

Sidebar

Related Questions

I need to assign a variable which will be used to create the id
I need a script in batch file which will get me yesterdays date into
http://example.com/foo.aspx?foo=bar I'm refactoring and need to name the constant which will hold only the
Is there any way to declare a variable at file scope (which will be
I need a test for a variable which would evaluate to true in two
I have a variable which I need to strip of sybols before inserting into
I have a PHP-variable called $go_Adress which contains the adress I need to get
I need a variable to hold results retrieved from the database. So far this
In a javascript file (e.g. script.js) I need a variable that contains the absolute
I have a variable which will contain a relative URL (i.e. ../test.html) and I

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.