2D行列の転置を探していて、2D配列と行列の値の数を入力および返す関数 を作成したい2D行列の転置。以下のよう 私はC++2D配列を関数パラメータとして与え、2D配列を関数の戻り値の型として返す
#include <iostream>
#include <string>
using namespace std;
//int** transpose(int arr[][] , int n);
int k=2;
int ** transpose(int wt[1][k] , int n)
{
int trans[n][1];
for(int i=0;i<n;i++)
{
trans[i][1] = wt[1][i];
}
return trans ;
}
int main()
{ int n;
cin >> n;
int wt_vect[1][n];
for(int i=0;i<n;i++)
{
wt_vect[1][i] = 0.7;
}
int trans[n][1] = transpose(wt_vect , n);
}
しかし、取得エラーログに次のコードを書かれている
7時30分:エラー:バインドされた配列は 7時32分のトークンの前に整数定数「]」ではありません。エラー:予期しない ')'前 '、'トークン ' 7:34:' int 'の前に予期しない非修飾IDがある
機能を使用して転置を見つけるのを手伝ってください。アドバンス
このヘルプをいているのですか? https://stackoverflow.com/questions/16449359/getting-error-array-bound-is-not-an-integer-constant-before-token –
int wt_vect [1] [n] '(ここで、 'n'は変数です)は(標準の)C++ではありません。 – max66
そして、 'wt_vect [1]'が** second ** elemenにアクセスするのを観察してください。 'wt_vect'の最初の次元が' 1'ならば 'wt_vect [0] [i]'と書いてください – max66