提问者:小点点

LNK2019和LNK1120错误,未解析的外部和未解析的符号


我一直在寻找这个答案大约4个小时和它的痛苦,到目前为止,我遇到了多个修复如何摆脱实际错误,我已经阅读了几乎2整版的先前海报LNK2019&;LNK1120错误,到目前为止我仍然不明白修复程序是如何工作的,我还没有包括任何外部库。我已经尝试找到我正在寻找的东西,但老实说我不明白我正在寻找什么,因为我还没有实现一个外部API或任何类似的东西,嗯,我不相信,这是我朋友的代码,所以我不知道他实现了什么,请帮助,还有,这是源代码太。

错误LNK2019无法解析的外部符号“void__cdecl displaySpace(int,class>;std::basic_string,class std::allocator>;,bool,char)”(?displaySpace@@yaxhv?$basic_string@du?$char_traits@d@std@@v?$allocator@d@2@@std@@_nd@z)在函数_main中引用

(还说在1号线)

LNK1120,1外部未解决(它还说它在1行)

#include <string>
#include <iostream>
#include <array>


using namespace std;

int main()
{
string userString;
const int maxWordLength = 32;
char userWord[maxWordLength];
char remainingLetters[26] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
int health = 0;
int wordLength = 0;
int letterFind = 0;
int index = 0;
bool gameOver = false;
bool inputValid = false;
bool inputValid2 = false;
char guessChar = ' ';
void displaySpace(int wordLength, string userWord, bool correctGuess, char guessChar);

while (!inputValid)
{
    //ask for pharse/word
    cout << "Player 1, pick a word or pharse less than (no caps) " << maxWordLength << " characters: " << endl;
    getline(cin, userString);
    //cout << userString << endl;

    wordLength = userString.length();
    // << wordLength << endl;

    if (wordLength <= maxWordLength)
    {
        //skips down so player 2 does not cheat
        for (int i = 0; i < 100; i++)
        {
            cout << " " << endl;
        }
        for (int i = 0; i < wordLength; i++)
        {
            userWord[i] = userString[i];
        }

        displaySpace(wordLength, userWord, false, guessChar);
        inputValid = true;
    }
    else
    {
        continue;
    }

    while (!gameOver)
    {
        cout << " " << endl;
        cout << "Player 2, guess a letter in the phrase/word: " << endl;
        cin >> guessChar;
        while (!inputValid2)
        {
            if (!isalpha(guessChar))
            {
                continue;
            }
            else
            {
                cin >> guessChar;
                for (int i = 0; i < wordLength; i++)
                {
                    if (userWord[i] == guessChar)
                    {
                        for (int k = 0; k < 26; k++)
                        {
                            if (remainingLetters[k] == guessChar)
                            {
                                for (index = k; index < 26; index++)
                                {
                                    int temp = remainingLetters[index];
                                    remainingLetters[index] = remainingLetters[index + 1];
                                    remainingLetters[index + 1] = temp;

                                }
                                for (int index = 0; index < k; index++)
                                {
                                    cout << remainingLetters[index] << " ";
                                }
                                for (int i = 0; i < 26; i++)
                                {
                                    cout << remainingLetters[i] << endl;
                                }

                            }
                            else
                            {
                                continue;
                            }
                        }
                    }
                    else
                    {

                    }
                }
                inputValid = true;
            }
        }
    }
}
return 0;
}    

void displaySpace(int wordLength, string userWord, bool correctGuess, char 
guessChar, char remainingLetters[26])
{
string displayspace[32]= {" "," ", " ", " ", " ", " ", " ", " ", " ", " ", " 
", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " 
", " ", " ", " ", " ", " ", " ", };
string space = "  ";
string dash = " _ ";
string guessString(1, guessChar);
cout << guessString << endl;

for (int i = 0; i < 32; i++) {
    displayspace[i] = "  ";
}

for (int i = 0; i < wordLength; i++)
{
    for (int k = 0; i < 26; i++) {
        if (remainingLetters[k] == userWord[i])
        {
            displayspace[i] = dash;
            cout << dash;
        }
    }

    if (correctGuess == true)
    {
        displayspace[i] = guessString;
        cout << guessString;
    }
    else
    {
        displayspace[i] = space;
        cout << space;
    }
}
for (int i = 0; i < wordLength; i++)
{
    cout << displayspace[i];
}

}


共1个答案

匿名用户

函数原型(和调用站点)之间存在不匹配:

void displaySpace(int wordLength, string userWord, bool correctGuess, char guessChar);

和实际函数定义:

void displaySpace(int wordLength, string userWord, bool correctGuess, char guessChar, char remainingLetters[26])

这就是编译器找不到匹配函数的原因。