我创建了一个继承自Controller类的Player类。这是一个用于控制游戏中单元的类。我用它得到了这个错误:
error: undefined reference to 'Controller::Controller()'
我不确定我在这里做错了什么。有谁知道出了什么问题?
由于
这是代码:
或者Controller.h
#ifndef CONTROLLER_H
#define CONTROLLER_H
class Controller;
#include <qDebug>
class Controller
{
public:
Controller();
virtual bool w();
virtual bool a();
virtual bool s();
virtual bool d();
virtual bool space();
private:
};
#endif // CONTROLLER_H
player.h
#ifndef PLAYER_H
#define PLAYER_H
class Player;
#include "controller.h"
#include "view/mainwindow.h"
#include <QString>
class Player : public Controller
{
public:
Player(QString name, MainWindow *window);
// Controller functions
bool w();
bool a();
bool s();
bool d();
bool space();
private:
QString name;
MainWindow *window;
};
#endif // PLAYER_H
player.cpp
#include "player.h"
Player::Player(QString name, MainWindow *window) {
this->name = name;
this->window = window;
}
bool Player::w() {return window->w();}
bool Player::a() {return window->a();}
bool Player::s() {return window->s();}
bool Player::d() {return window->d();}
bool Player::space() {return window->space();}