2012-02-09 121 views
1

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

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

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

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

回答

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

由于编译器认为该声明首先,它会用它来解决该块中的通话的代码。但是,该函数不会导出,因为它具有不同的签名。

+0

Ahhh darn,我忘了更改它。谢谢你的收获! – Sam 2012-02-10 00:06:53

+0

@Sam那是它吗?诚实地猜测,最近发生在我身上。当我在声明中遗漏了一个'const'时,半个小时我正在查看'.lib'文件。 :) – 2012-02-10 00:10:03

+0

是的,你懂了,嘿嘿。 – Sam 2012-02-10 00:16:35

0
在解决游戏

b[36][4] 

在可移动

b[36][3] 

可能产生问题。

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) ... 
相关问题