【发布时间】:2015-10-06 05:44:13
【问题描述】:
#include <bits/stdc++.h>
using namespace std;
#define HODOR long long int
#define INF 1234567890
#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define dwn(i, a, b) for(int i = (a); i >= (b); --i)
#define REP(c, it) for( typeof( (c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define DWN(c, it) for( typeof( (c).end()) it = (c).end()-1; it >= (c).begin(); --it)
#define ss(n) scanf("%s",n)
#define FILL(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define mp make_pair
#define ALL(v) v.begin(), v.end()
#define sz(a) ((int)a.size())
#define SET(v, i) (v | (1 << i))
#define TEST(v, i) (v & (1 << i))
#define TOGGLE(v, i) (v ^ (1 << i))
#define gc getchar
#define pc putchar
template<typename X> inline void inp(X &n ) {
register int ch=gc();int sign=1;n=0;
while( ch < '0' || ch > '9' ){if(ch=='-')sign=-1; ch=gc();}
while( ch >= '0' && ch <= '9' ) n = (n<<3)+(n<<1) + ch-'0', ch=gc();
n=n*sign;
}
inline void inps(char *n) {
register int ch=gc();
int sign=1;
int i=0;
while( ch != '\n' ){ n[i]=(char)ch; ++i; ch=gc();}
n[i]='\0';
}
int MaxPath(int arr[][100],int n) {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
cout<<arr[i][j]<<" ";
}
cout<<endl;
}
}
int main() {
int t,n;
inp(t);
while(t--) {
inp(n);
int arr[n][n];
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
inp(arr[i][j]);
}
}
float result = MaxPath(arr,n);
}
return 0;
}
错误看起来像这样: 错误:无法将参数 '1' 的 'int ()[n]' 转换为 'int ()[100]' 到 ' int MaxPath(int (*)[100], int)'
我在 stckoverflow 上看过很多帖子,但似乎都没有工作
【问题讨论】:
-
我强烈建议您使用文本编辑器的 sn-ps 功能而不是那些宏。按位的很容易成为函数而不是宏,或者您可以使用
std::bitset。 -
代码现在缩进很好
-
我认为 arr[n][n] 应该是 arr[][100]。编译器必须知道二维数组的一行元素数。在这种特定情况下,您还可以使用指向指针的指针来传递二维数组的地址。
-
你能不能把它作为一个指针传递给一个指向 int
int** arr的指针 -
@bhzag 我试过
int** arr错误:无法转换int (*)[n]’ to ‘int**
标签: c++ arrays parameter-passing