Redefintion Errors

I am working on a program that simulates a game of GoFish. I have a weird error that is making it difficult to make any progress. I get the following error when building "error: redefinition of 'Player'." I have looked at various websites regarding the error, but it seems as if all of the code includes the cpp in the header and the header in the cpp. However, mine does not.

Here is the .cpp file:

 #include "player.h"


    myName = "";


Player::Player(string name) {

    myName = name;


string Player::getName() const {

    return myName;


I have excluded the methods which aren't giving errors.

Additionally, here is the .h file:


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

#include "card.h"
using namespace std;

class Player

     Player(string name) {
        myName = name;

    string getName() const {
       return myName;

    void addCard(Card c);  //adds a card to the hand
    void bookCards(Card c1, Card c2);
    bool checkHandForBook(Card &c1, Card &c2);
    bool rankInHand(Card c) const;
    Card chooseCardFromHand() const;
    bool cardInHand(Card c) const;
   Card removeCardFromHand(Card c);

    string showHand() const;
    string showBooks() const;

   int getHandSize() const;
   int getBookSize() const;


    vector <Card> myHand;
    vector <Card> myBook;

    string myName;



The only two function which are getting redefinition errors are the constructor and getName. What could be causing this?

1 answer

  • answered 2018-11-08 05:35 user1118321

    You've included the entire constructor and getName() function in the header and in the .cpp file. They should only exist in one or the other.