错误是这样的:
无法将参数 1' 的
bool permission(int*, int, int)'
在代码中我有一个 int board[n],用户给出了 'n'...
我想给我的许可函数这个数组,所以我不得不通过指针给它,因为它的长度没有指定......那么我该如何解决这个问题
这是我的代码:int*' 转换为
int*' to
#include <cstdlib>
#include <iostream>
#include <cmath>
using namespace std;
bool permition(int* board[],int place,int n_){
int m=place;
while(m!=0){
m--;
if(abs(abs(board[m]-board[place])-abs(m-place))==1
&& abs(m-place)<3 && abs(board[m]-board[place]))
return false;
}
return true;
}
void printBoard(int* board[],int n){
for(int i=0;i<n;i++)
cout << board[i]<< " ";
cout << endl;
}
int main()
{
int p=0;
int n;
cout << "plz: ";
cin >> n;
int board[n];
for(int i=0;i<n;i++)
board[i]=0;
while(p<n){
while((board[p]<n) && permition(board,p,n)==false)
board[p]+=1;
if(board[p]<n)
p++;
else{
p--;
board[p]+=1;
}
if(p==n && board[0]<n-1)
//it means the first number is not max so we should
//print and continue from fist again
{
printBoard(board,n);
p=0;
board[0]+=1;
}
}
system("PAUSE");
return 0;
}
最佳答案
去掉permission函数定义中的[]:
bool permition(int* board,int place,int n_)
看看有没有帮助!
关于c++ - 当我在函数参数中使用指针时遇到错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22287970/