Seb Seb - 1 month ago 7
C++ Question

error: redefinition of 'paddlePlayer'

I keep getting this error:


redefinition of 'paddlePlayer' paddlePlayer::paddlePlayer(int playerNumber)



I also get the error:


out-of-line definition of 'Update' does not match any declaration in 'paddlePlayer'
void paddlePlayer::Update()



My cpp file is as follows:

#include "paddleplayer.h"

paddlePlayer::paddlePlayer(int playerNumber)
{
this->playerNumber = playerNumber;
switch (this->playerNumber)
{
case 0:
break;
default:
break;
}
}

void paddlePlayer::Update()
{
switch (this->playerNumber)
{
case 0:
break;
default:
break;
}
}


And my header file looks like this:

#ifndef HAND_IN_5_1_PADDLEPLAYER_H
#define HAND_IN_5_1_PADDLEPLAYER_H

#include "entity.h"

class paddlePlayer : public Entity
{
public:
paddlePlayer(int playerNumber)
{
this->playerNumber = playerNumber;
void Update();

}

protected:
int playerNumber;
};

#endif


Any tips?

Answer

Theres a few errors in your header:

#ifndef HAND_IN_5_1_PADDLEPLAYER_H
#define HAND_IN_5_1_PADDLEPLAYER_H

#include "entity.h"

class paddlePlayer : public Entity
{
public:
    paddlePlayer(int _playerNumber); //Wasn't declared correctly and you shouldn't give the same name to a parameter that is an attribute of your class
    void Update(); // Was declared inside your constructor definition...

protected:
    int playerNumber;
};
Comments