尝试在函数内初始化全局 c++ 矩阵(二维数组)时遇到了这个问题:
这就是我正在做的
#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
......
}
我只得到一堆
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 '}'
我做错了什么或 C++ 限制?