// temp.cpp : Defines the entry point for the console application.
//#include "stdafx.h"int convert(int b[]);int main(int argc, char* argv[])
{
int a[3][6];
a[0][0] = 1;
a[0][1] = 2;
a[0][2] = 3;
a[1][0] = 4;
a[1][1] = 5;
a[1][2] = 6;
a[2][0] = 7;
a[2][1] = 8;
a[2][2] = 9; convert( a );
return 0;
}int convert(int b[])
{
int i,j;
int num; for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
num = b[i*3+j];
printf("hello %d\n",num);
} return 1;
}
错误提示::\My Documents\zej\temp\temp.cpp(22) : error C2664: 'convert' : cannot convert parameter 1 from 'int [3][6]' to 'int []'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.如何修改可以运行
//#include "stdafx.h"int convert(int b[]);int main(int argc, char* argv[])
{
int a[3][6];
a[0][0] = 1;
a[0][1] = 2;
a[0][2] = 3;
a[1][0] = 4;
a[1][1] = 5;
a[1][2] = 6;
a[2][0] = 7;
a[2][1] = 8;
a[2][2] = 9; convert( a );
return 0;
}int convert(int b[])
{
int i,j;
int num; for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
num = b[i*3+j];
printf("hello %d\n",num);
} return 1;
}
错误提示::\My Documents\zej\temp\temp.cpp(22) : error C2664: 'convert' : cannot convert parameter 1 from 'int [3][6]' to 'int []'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.如何修改可以运行
{
int i,j;
int num; for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
//num = b[i*3+j];
printf("hello %d\n",b[i][j]);
} return 1;
}
{
int i,j;
int num; for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
num = b[i*3][j];
printf("hello %d\n",num);
} return 1;
}
C:\My Documents\zej\temp\temp.cpp(22) : error C2664: 'convert' : cannot convert parameter 1 from 'int [3][6]' to 'int [][1]'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
C:\My Documents\zej\temp\temp.cpp(26) : error C2087: '<Unknown>' : missing subscript
Error executing cl.exe.temp.exe - 3 error(s), 0 warning(s)
{
int a[3][6];
a[0][0] = 1;
a[0][1] = 2;
a[0][2] = 3;
a[1][0] = 4;
a[1][1] = 5;
a[1][2] = 6;
a[2][0] = 7;
a[2][1] = 8;
a[2][2] = 9; convert( a );
return 0;
}int convert(int* b)
{
int i,j;
int num; for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
num = b[i*3+j];
printf("hello %d\n",num);
} return 1;
}
convert(a[0]);
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.temp.exe - 1 error(s), 0 warning(s)
convert(a[1]);
.............//依此类推.
调用时改为:
convert(a[0]);
{
int a[3][3];
a[0][0] = 1;
a[0][1] = 2;
a[0][2] = 3;
a[1][0] = 4;
a[1][1] = 5;
a[1][2] = 6;
a[2][0] = 7;
a[2][1] = 8;
a[2][2] = 9; convert( (int *)&a );
return 0;
}int convert(int* b)
{
int i,j;
int num; for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
num = b[i*3+j];
printf("hello %d\n",num);
} return 1;
}