user2925521
user2925521

Reputation: 11

error LNK2019: unresolved external symbol newbie needs tip

I am just probing some more advanced coding in C++, so imagine my frustration when I can't solve this:

1>Main.obj : error LNK2019: unresolved external symbol "int __cdecl playerAtk(void)" (?       playerAtk@@YAHXZ) referenced in function _main
1>C:\Users\Hezekiah Detinc\documents\visual studio 2010\Projects\Custom_1\Debug\Custom_1.exe : fatal error LNK1120: 1 unresolved externals

I had tried searching for an answer here, but the solutions I have found were too specific to be of any use for me.

If anyone can answer; What generally causes this problem? What are some solutions to fixing it?

This is my Main.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;
}

If I need to post my headers or the other _.cpp files, let me know.

Upvotes: 0

Views: 159

Answers (2)

Andreas Goulas
Andreas Goulas

Reputation: 163

You declare and use playerAtk as a function (with no implementation, thus the undefined reference)

Change

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

to

int playerAtk;
...
cout << playerAtk;

(You probably want to initialize the variable)

Upvotes: 2

Manu343726
Manu343726

Reputation: 14184

The error is simple: You are using a function which you have declared, but you have not written any definition (Implementation). Check your source (.cpp) files.

Upvotes: 0

Related Questions