错误:重新定义' paddlePlayer'

时间:2016-10-12 14:38:18

标签: c++

我一直收到这个错误:

  

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

我也得到错误:

  

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

我的cpp文件如下:

#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;
    }
}

我的头文件如下所示:

#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

任何提示?

1 个答案:

答案 0 :(得分:2)

标题中有一些错误:

#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;
};