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