我将矩阵与其函数转置的未定义引用相乘(.....) 请告诉我我错在哪里。 我知道我的代码很乱,但我正在为midterms做准备,这就是为什么我匆忙并继续编辑同一个文件可能就是为什么我找不到错误
这是我的代码:
#include<iostream>
#include<fstream>
using namespace std;
void transpose(int arr[][10],int trans[][10],int ar[][1],int,int);
void output(int,int);
int main()
{
int array[10][10]={0};
int trans[10][10]={0};
int array5[3][1]={4,5,6};
ifstream input("matrix.txt");
int rows=0,col=0,num=0;
char ch;
int x=0,z=0;
//Finding Numbers of rows and columns
for(col=0;ch!='\n';col++)
{
input>>array[0][col];
input.get(ch);
}
input.close();
ifstream input1("matrix.txt");
while(!input1.eof())
{
input1>>array[z][x];
input1.get(ch);
if(ch=='\n')
{
rows++;
z++;
}
x++;
}
rows=rows+1;
cout<<"Oye"<<rows<<" "<<col<<endl;;
input.close();
ifstream srch("matrix.txt");
for(int r=0;r<rows;r++)
{
for(int c=0;c<col;c++)
{
srch>>array[r][c];
cout<<array[r][c]<<" ";
}
cout<<endl;
}
cout<<endl<<endl;
cout<<"=================================================" <<endl;
transpose(array,trans,array5,rows,col);
input.close();
}
void transpose(int arr[][10],int trans[][10],int ar[][10],int row,int col)
{
int x=0,y=0,flag=0,row1=0,j=0;
for(row1=0;row1<row;row1++)
{
trans[row][j]=0;
for(j=0;j<col;j++)
{
for(int k=0;k<col;k++)
trans[row][j]=trans[row][j]+(arr[row1][j]*ar[k][j]);
}
}
for(int r=0;r<row;r++)
{
for(int c=0;c<col;c++)
{
cout<<trans[r][c]<<" ";
}
cout<<endl;
}
}
答案 0 :(得分:1)
函数原型不匹配。
void transpose(int arr[][10],int trans[][10],int ar[][1],int,int);
void transpose(int arr[][10],int trans[][10],int ar[][10],int row,int col)
^^
为什么要写int array5[3][1]={4,5,6};
?您可以将其设为int array5[3]={4,5,6};
,函数将如下所示:
void transpose(int arr[][10],int trans[][10],int ar[],int row,int col);