LNK2019 error, unresolved external symbol

大憨熊 提交于 2019-12-08 02:47:54

问题


The error verbatim reads

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)

I've never seen this error before. Here are the two functions I believe it's referring to though.

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;
}

and

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);
    }
}

回答1:


Your current declaration doesn't match the definition.

You probably have declared the function availableMoves() before you use it, but then you implement a different function:

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)
{
    //....
}

Since the compiler sees that declaration first, it will use it to resolve the call in the block of code. However, that function is not exported, as it has a different signature.




回答2:


in solved game

b[36][4]

in available moves

b[36][3]

that could create a problem.




回答3:


Nice one: you use incompatible array dimensions! Note that part of the error message reads

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

While the definition of availableMoves() looks like this:

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

Although the first dimension of the arguments is ignored, all other dimensions have to match exactly. You try to call this function with incompatible dimensions, however:

void solveGame(int a[15], int b[36][4]){
    ...
    ... availableMoves(a,b,empSpace) ...


来源:https://stackoverflow.com/questions/9220829/lnk2019-error-unresolved-external-symbol

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!