2

错误逐字读取

1>yes.obj : error LNK2019: unresolved external symbol "int __cdecl availableMoves(int *     const,int (* const)[4],int)" (?availableMoves@@YAHQAHQAY03HH@Z) referenced in function "void __cdecl solveGame(int * const,int (* const)[4])" (?solveGame@@YAXQAHQAY03H@Z)

我以前从未见过这个错误。这是我认为它所指的两个功能。

int availableMoves(int a[15], int b[36][3],int openSpace){
    int count=0;
    for(int i=0; i<36;i++){
        if(i < 36 && b[i][2] == openSpace && isPeg(b[i][0],a) && isPeg(b[i][1],a) ){
            count++;
        }
    }
    return count;
}

void solveGame(int a[15], int b[36][4]) {
    int empSpace;
    int movesLeft;
    if(pegCount(a) < 2) {
        cout<<"game over"<<endl;
    } else {
        empSpace = findEmpty(a);
        if(movesLeft = availableMoves(a,b,empSpace) < 1 ) {
            temp[index] = empSpace;
            d--;
            c[d][0] = 0;
            c[d][1] = 0;
            c[d][2] = 0;
            c[d][3] = 0;
            a[b[c[d][3]][0]] = 1;
            a[b[c[d][3]][0]] = 1;
            a[b[c[d][3]][0]] = 0;
            b[c[d][3]][3] = 0;
            index++;
        } else if(movesLeft >= 1) {
            chooseMove( a, b, empSpace);
            index = 0;
            for(int i=0; i<4; i++) {
                temp[i] = -1;
            }
        }
        d++;
        solveGame( a, b);
    }
}
4

3 回答 3

3

您当前的声明与定义不符。

您可能availableMoves()在使用它之前已经声明了该函数,但随后您实现了一个不同的函数:

int availableMoves(int* const a, int (* const)[4] , int);


//....
//....
//....
//code that uses available moves


int availableMoves(int a[15], int b[36][3],int openSpace)
{
    //....
}

由于编译器首先看到该声明,它将使用它来解析代码块中的调用。但是,该函数不会导出,因为它具有不同的签名。

于 2012-02-10T00:03:53.570 回答
0

在已解决的游戏中

b[36][4]

在可用的动作中

b[36][3]

这可能会造成问题。

于 2012-02-10T00:05:36.167 回答
0

不错的一个:您使用不兼容的数组维度!请注意,部分错误消息显示为

availableMoves(int *const,int (*const)[4],int)

虽然 的定义availableMoves()看起来像这样:

int availableMoves(int a[15], int b[36][3],int openSpace)

尽管参数的第一个维度被忽略,但所有其他维度必须完全匹配。您尝试使用不兼容的尺寸调用此函数,但是:

void solveGame(int a[15], int b[36][4]){
    ...
    ... availableMoves(a,b,empSpace) ...
于 2012-02-10T00:07:19.410 回答