質問概要
C++にて関数定義を試みているのですが、なぜかうまくいきません。
配列を引数にしていますが、そこでエラーが出てしまいます。
また、カウント変数としてi,jを定義していますが宣言していないことになっているようです。
実現したいこと
単に行列の各要素を手入力してもらい、入力された行列を一覧として表示するだけです。
手入力に関する処理を関数として独立させようとしています。
しかし、引数であるカウント変数と二次元配列の箇所で謎のエラーが出てしまいます。
発生している問題・エラーメッセージ
PS C:\Users\motch\java> g++ Function1_C++_20221223.cpp -o Function1_C++_20221223 ; .\Function1_C++_20221223 Function1_C++_20221223.cpp:6:44: error: array bound is not an integer constant before ']' token double matrix_input(int i,int j,double x[NN][NN]); ^ Function1_C++_20221223.cpp:6:48: error: array bound is not an integer constant before ']' token double matrix_input(int i,int j,double x[NN][NN]); ^ Function1_C++_20221223.cpp:62:44: error: array bound is not an integer constant before ']' token double matrix_input(int i,int j,double x[NN][NN]) ^ Function1_C++_20221223.cpp:62:48: error: array bound is not an integer constant before ']' token double matrix_input(int i,int j,double x[NN][NN]) ^ Function1_C++_20221223.cpp: In function 'double matrix_input(...)': Function1_C++_20221223.cpp:64:20: error: 'i' was not declared in this scope cout << "x["<< i <<"]["<< j <<"]?----------->"; ^ Function1_C++_20221223.cpp:64:31: error: 'j' was not declared in this scope cout << "x["<< i <<"]["<< j <<"]?----------->"; ^ Function1_C++_20221223.cpp:65:12: error: 'x' was not declared in this scope cin >> x[i][j];
該当のソースコード
以下がソースコードの冒頭の抜粋です。
C++
1#include <iostream> 2using namespace std; 3int NN=10; 4 5 6double matrix_input(int i,int j,double x[NN][NN]); 7//double matrix_display 8//double matrix_multiple 9
以下が関数の定義部分です。
C++
1double matrix_input(int i,int j,double x[NN][NN]) 2{ 3 cout << "x["<< i <<"]["<< j <<"]?----------->"; 4 cin >> x[i][j]; 5 6 return x[i][j]; 7 8}
いずれも
double matrix_input(int i,int j,double x[NN][NN]);
に問題があるようです。
試したこと、確認したこと
教科書を見直しましたが、この書き方で間違っていないようです。
何が原因なのでしょうか???
以上よろしくお願いいたします。

回答2件
あなたの回答
tips
プレビュー