c++问题:error C2664: 'assign' : cannot convert parameter 1 from 'tripletable [2][3]' to 'int [][3]

来源:百度知道 编辑:UC知道 时间:2024/06/22 00:45:04
#include "stdafx.h"
#include "iostream.h"
#include "stdlib.h"
#include "conio.h"

# define MAXSIZE 1000
//#define int DataType;
typedef struct
{ int i,j,v;
}triple;

typedef struct
{
triple data[MAXSIZE];
int m,n,t;
}tripletable;

void assign(int A[2][3],tripletable B)
{ int total=0;
for(int i=0;i<1;i++)
for(int j=0;j<2;j++)
if(A[i][j]!=0)
{
B.data[total].i=i;
B.data[total].j=j;
B.data[total].v=A[i][j];
total++;
}

}

int main(int argc, char* argv[])
{
triple B;
tripletable A[2][3]={0,0,3,0,5,0};

int i,j;
assign(A,B);
}

就是错了。你在主程序中定义的变量A是tripletable类型,然后在函数assign中使用了变量A.但是在这个函数assigne的定义中void assign(int A[2][3],tripletable B),你把第一个参数定义为了int型。这样,同一个函数,使用了不同的参数类型。肯定就错了。你把这个改一致就可以了。

int main(int argc, char* argv[])
{
triple B;//这个改成tripletable B;就行了
tripletable A[2][3]={0,0,3,0,5,0};

int i,j;
assign(A,B);
}
void assign(int A[2][3],tripletable B)//这个也得改int 改成tripletable

int A[2][3]改成tripletable A[2][3]应该就可以了,不过不推荐使用多元定长数组。。。