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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:02:17+00:00 2026-06-12T17:02:17+00:00

I got this problem when trying to initialize global c++ matrix(2D array) inside a

  • 0

I got this problem when trying to initialize global c++ matrix(2D array) inside a function:

here is what I’m doing

#include <iostream>
#include <math.h>
#include <Windows.h>

using namespace std;

float matrix[5][5];

void setIR(){
    matrix[5][5]= {
        { 17.2, 22.75, 2.5, -9.15, 0.2},
        { 22.75, 145.5, 9.25, 20.75, 5.25 },
        { 2.5, 9.25, 76.5, -15.5, -6.0 },
        { -9.15, 20.75, -15.5, 37.3, -25.65 },
        { 0.2, 5.25, -6.0, -25.65, 41.2 }
        };

int main(){
//rest of the code
......
}

I’m getting only bunch of

1>c:\users\apple\documents\visual studio 2010\projects\jcb\jcb\jcbPIO.cpp(46): error C2059: syntax error : '{'
1>c:\users\apple\documents\visual studio 2010\projects\jcb\jcb\jcbPIO.cpp(46): error C2143: syntax error : missing ';' before '{'
1>c:\users\apple\documents\visual studio 2010\projects\jcb\jcb\jcbPIO.cpp(47): error C2143: syntax error : missing ';' before '}'
1>c:\users\apple\documents\visual studio 2010\projects\jcb\jcb\jcbPIO.cpp(47): error C2143: syntax error : missing ';' before ','
1>c:\users\apple\documents\visual studio 2010\projects\jcb\jcb\jcbPIO.cpp(48): error C2143: syntax error : missing ';' before '{'
1>c:\users\apple\documents\visual studio 2010\projects\jcb\jcb\jcbPIO.cpp(48): error C2143: syntax error : missing ';' before '}'
1>c:\users\apple\documents\visual studio 2010\projects\jcb\jcb\jcbPIO.cpp(48): error C2143: syntax error : missing ';' before ','
1>c:\users\apple\documents\visual studio 2010\projects\jcb\jcb\jcbPIO.cpp(49): error C2143: syntax error : missing ';' before '{'
1>c:\users\apple\documents\visual studio 2010\projects\jcb\jcb\jcbPIO.cpp(49): error C2143: syntax error : missing ';' before '}'
1>c:\users\apple\documents\visual studio 2010\projects\jcb\jcb\jcbPIO.cpp(49): error C2143: syntax error : missing ';' before ','
1>c:\users\apple\documents\visual studio 2010\projects\jcb\jcb\jcbPIO.cpp(50): error C2143: syntax error : missing ';' before '{'
1>c:\users\apple\documents\visual studio 2010\projects\jcb\jcb\jcbPIO.cpp(50): error C2143: syntax error : missing ';' before '}'
1>c:\users\apple\documents\visual studio 2010\projects\jcb\jcb\jcbPIO.cpp(50): error C2143: syntax error : missing ';' before ','
1>c:\users\apple\documents\visual studio 2010\projects\jcb\jcb\jcbPIO.cpp(51): error C2143: syntax error : missing ';' before '{'
1>c:\users\apple\documents\visual studio2010\projects\jcb\jcb\jcbPIO.cpp(51): error C2143: syntax error : missing ';' before '}'

I’m doing something wrong or C++ limitation ?

  • 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-12T17:02:18+00:00Added an answer on June 12, 2026 at 5:02 pm

    This “list assignment” syntax only works for initialization (that is, at the place where you define the variable), not for assignment. What your assignment statement tries to do is to assign to the single element matrix[5][5] (which doesn’t actually exist) a values given by the curly braces list, which isn’t a valid syntax for a value.

    You can assign the matrix as follows:

    float matrix[5][5];
    
    void setIR()
    {
      static float const values[5][5]= {
            { 17.2, 22.75, 2.5, -9.15, 0.2},
            { 22.75, 145.5, 9.25, 20.75, 5.25 },
            { 2.5, 9.25, 76.5, -15.5, -6.0 },
            { -9.15, 20.75, -15.5, 37.3, -25.65 },
            { 0.2, 5.25, -6.0, -25.65, 41.2 }
            };
      for (int i = 0; i < 5; ++i)
        for (int j = 0; j < 5; ++j)
          matrix[i][j] = values[i][j];
    }
    

    Of course, given that your values are constants anyway, the best solution is to just give them in the definition of matrix itself. That also saves the time to copy all the data.

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

Sidebar

Related Questions

I've got this odd problem with jQuery. I'm trying to let the change of
I got stuck with this problem. I wrap two tables inside of a h:form.
I've got this problem when trying to construct a variable name (which should output
Ok. I got this problem I trying to remove the last slash in a
I've got this problem that It always hit the PropertyAccessException when trying to saveOrUpdate();
I got this problem after deploying my web package to IIS: HTTP Error 500.19
Ive got this problem: Line 20 (LOOT_FromContainer(container) I need that to use as Invoke
I got this problem with AVAudioRecorder not working for me, at least from what
I've got this problem for a while now and I cannot find a solution
ok i got this problem. i have this routes: (code bit change) File:/home/dotcloud/current/config/routes.js exports.routes

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.