-1

I'm getting three errors which I don't understand. The first one says:

"Player::Player()", referenced from:
    Hangman::Hangman() in hangman.o. 

The second one says:

"vtable for Hangman", referenced from:
    Hangman::Hangman() in hangman.o

And the last one says:

Hangman::~Hangman() in main.o.

Can someone help me out?

In my headerfile I have:

     #ifndef PLAYER_H_
     #define PLAYER_H_

    #include <iostream>
    #include <string>
    #include <vector>

    using namespace std;

    class Player{

    public:
        Player();
        char MakeGuess();
        void Win();
        void Lose();
        char Agree();
    private:
        string name;
        int score;
    };
#endif

In my other headerfile I have 


#ifndef HANGMAN_H_
#define HANGMAN_H_
#include <iostream>
#include <string>
#include <vector>
#include "player.h"

using namespace std;

class Hangman
{
public:
    Hangman();
    void Play();
protected:
    Player player2;
    vector<string> words;
    int wrong;
    const int maxwrong=4;
    char guess;
    void virtual RespondIncorrectGuess();
};

 #endif

In my main function in a different file I have:

#include <iostream>
#include <string>
#include <vector>
#include "player.h"
#include "hangman.h"

using namespace std;

int main()
{
    Hangman test;

    test.Play();
}
Brendan Green
  • 11,676
  • 5
  • 44
  • 76
Brogrammer93
  • 97
  • 1
  • 2
  • 9

1 Answers1

0

Those are linker errors, not compiler errors. You need to find the source file that contains the definitions of the class Player functions declared in the header file, then add that to be compiled and linked in your project. The file you need is probably called Player.cpp.

Dan Korn
  • 1,274
  • 9
  • 14
  • Im positive I have the player file added to be complied – Brogrammer93 Jun 11 '15 at 21:24
  • @Darraptor The error messages contain the phrase "undefined symbol" or "undefined reference", which means you're calling a function or referring to a variable that has no definition. So, as the linker error says, you're missing the definition for the `Player` constructor, whereas "undefined reference to vtable" usually means you're missing the definition for a virtual function (vtable = virtual table). I can't see the definition of `RespondIncorrectGuess` which is virtual so that must be the culprit. – Emil Laine Jun 11 '15 at 21:25
  • Thank you Zenith I was able to fix the issue! Also thank you Dan Korn for being there and anyone else who i might of missed!! – Brogrammer93 Jun 11 '15 at 21:35