简体   繁体   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;
}

I am trying to multiply two matrices in this code, but this statement is creating a major problem.我试图在这段代码中将两个矩阵相乘,但这条语句造成了一个主要问题。 Please tell how to solve this error.请告诉如何解决这个错误。 it is giving me error in the line m[i][j] = a[i][j]*b[j][i]);它在m[i][j] = a[i][j]*b[j][i]);

Your code previously had few minor bugs, like missing } .您的代码以前有一些小错误,例如缺少} Here I have corrected it.在这里我已经更正了。

#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;
}

Things I have changed:-我改变的事情: -

  1. Added { at line no 35在第 35 行添加{
  2. Changed the name of the third array.更改了第三个数组的名称。 Where the result is to be stored.结果存储在哪里。 Actually, there was an ambiguity due to the name of the variable and the 2-d array being the same.实际上,由于变量名称和二维数组相同,因此存在歧义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM