簡體   English   中英

誰能解釋為什么我在以下代碼中得到“表達式必須有指向 object 類型的指針”:

[英]Can anyone explain why am i getting “expression must have pointer to object type” in the following code:

#include<iostream>
#include<conio.h>
#include<array>

using namespace std;
int main(){
    system("cls");
    int n, l, m;
    int a[100][100], b[100][100], m[100][100];
    //inputing
    cout<<"For the multiplication of the matrices NxL & LxM: \n";
    cout<<"Enter N: ";
    cin>>n;
    cout<<"Enter L: ";
    cin>>l;
    cout<<"Enter M: ";
    cin>>m;
    cout<<"Enter the first matrix: ";
    for(int i=0; i<n; i++){
        for(int j=0; j<l; j++){
            cout<<i<<":";
            cin>>a[i][j];
        }
        cout<<"         \n";
    }
    cout<<"Enter the second matrix: ";
    for(int i=0; i<l; i++){
        for(int j=0; j<m; j++){
            cout<<i<<":";
            cin>>a[i][j];
        }
        cout<<"         \n";
    }
    //multiplying
    for(int i=0; i<n; i++)
        for(int j=0; j<l; j++){
            m[i][j] = a[i][j]*b[j][i]);
        }
    }
    getch();
    system("cls");
    return 0;
}

我試圖在這段代碼中將兩個矩陣相乘,但這條語句造成了一個主要問題。 請告訴如何解決這個錯誤。 它在m[i][j] = a[i][j]*b[j][i]);

您的代碼以前有一些小錯誤,例如缺少} 在這里我已經更正了。

#include<iostream>
#include<array>
#include<conio.h>

using namespace std;
int main(){
    system("cls");
    int n, l, m;
    int a[100][100], b[100][100], ar[100][100];
    //inputing
    cout<<"For the multiplication of the matrices NxL & LxM: \n";
    cout<<"Enter N: ";
    cin>>n;
    cout<<"Enter L: ";
    cin>>l;
    cout<<"Enter M: ";
    cin>>m;
    cout<<"Enter the first matrix: ";
    for(int i=0; i<n; i++){
        for(int j=0; j<l; j++){
            cout<<i<<":";
            cin>>a[i][j];
        }
        cout<<"         \n";
    }
    cout<<"Enter the second matrix: ";
    for(int i=0; i<l; i++){
        for(int j=0; j<m; j++){
            cout<<i<<":";
            cin>>a[i][j];
        }
        cout<<"         \n";
    }
    //multiplying
    for(int i=0; i<n; i++){
        for(int j=0; j<l; j++){
            ar[i][j] = a[i][j]*b[j][i];
        }
    }
    getch();
    system("cls");
    return 0;
}

我改變的事情: -

  1. 在第 35 行添加{
  2. 更改了第三個數組的名稱。 結果存儲在哪里。 實際上,由於變量名稱和二維數組相同,因此存在歧義。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM