LNK2019 错误,无法解析的外部符号

发布于 2025-01-03 19:40:23 字数 1490 浏览 6 评论 0原文

错误逐字显示

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

残龙傲雪 2025-01-10 19:40:23

您当前的声明与定义不匹配。

您可能在使用函数 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)
{
    //....
}

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

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.

夜吻♂芭芘 2025-01-10 19:40:23

在已解决的游戏中

b[36][4]

,可用的动作

b[36][3]

可能会产生问题。

in solved game

b[36][4]

in available moves

b[36][3]

that could create a problem.

一杯敬自由 2025-01-10 19:40:23

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

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) ...

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) ...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文