![](/img/trans.png)
[英]Why am I getting expression must have pointer to class type in c++?
[英]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;
}
我改變的事情: -
{
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.