错误LNK2019:未解析的外部符号新手需要提示

error LNK2019: unresolved external symbol newbie needs tip

本文关键字:新手 符号 提示 外部 LNK2019 错误      更新时间:2023-10-16

我只是在C++中探索一些更高级的编码,所以想象一下当我无法解决这个问题时的沮丧:

1>Main.obj : error LNK2019: unresolved external symbol "int __cdecl playerAtk(void)" (?       playerAtk@@YAHXZ) referenced in function _main
1>C:UsersHezekiah Detincdocumentsvisual studio 2010ProjectsCustom_1DebugCustom_1.exe : fatal error LNK1120: 1 unresolved externals

曾尝试在这里寻找答案,但我找到的解决方案太具体了,对我没有任何用处。

如果有人能回答;通常是什么原因导致此问题?修复它有哪些解决方案?

这是我的主要.cpp;

//Custom 1
//Include files that may be used. will cut out unused files in release.
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include "EnemyBaseClass.h"
#include "PlayerBaseClass.h"
using namespace std;
int main()
{
    Enemy emy;
    Player plr;
    emy.enemyAtk();
    emy.enemyDef();
    emy.enemyHp();
    plr.playerAtk();
    plr.playerDef();
    plr.playerHp();
    int playerAtk();
    cout << playerAtk();

    cout << "You're attacked by a Monster!n";
    system(" pause ");
    return 0;
}

如果我需要发布我的标题或其他 _.cpp 文件,请告诉我。

你声明并使用playerAtk作为一个函数(没有实现,因此是未定义的引用)

改变

int playerAtk();
...
cout << playerAtk();

int playerAtk;
...
cout << playerAtk;

(您可能想要初始化变量)

错误很简单:您正在使用已声明的函数,但尚未编写任何定义(实现)。检查源 (.cpp) 文件。