我收到三个我不明白的错误。第一个说:C++错误代码将不会链接
"Player::Player()", referenced from:
Hangman::Hangman() in hangman.o.
第二个说:
"vtable for Hangman", referenced from:
Hangman::Hangman() in hangman.o
,最后一个云:
Hangman::~Hangman() in main.o.
有人能帮助我吗?
在我headerfile我:
#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
在我的主要功能在不同的文件中,我有:
#include <iostream>
#include <string>
#include <vector>
#include "player.h"
#include "hangman.h"
using namespace std;
int main()
{
Hangman test;
test.Play();
}
你需要[include guard](http://stackoverflow.com/questions/14485215/c-class-redefinition-error-help-me-understand-headers-and-linking)。 –
@CaptainObvlious你的意思是indef#thingy?我如何包括警卫 – Brogrammer93
阅读链接:\ –