I'm from a java background and I'm trying to learn C++ with QT trying to make a tic tac toe game. I have problems with initializing objects within a certain class : I want the MainWindow class to have a Player instance and initialize Player by calling it's constructor but I don't understand the errors
#ifndef PLAYER_H
#define PLAYER_H
#include "board.h"
#include <qstring.h>
class Player
{
public:
QString token;
Player(QString);
void jouerCoup(int,int, Board&);
};
#endif // PLAYER_H
And this is the MainWindow class
#include <qstring.h>
#include "player.h"
#include "board.h"
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
Player aPlayer;
private:
Ui::MainWindow *ui;
private slots:
void buttonHandle();
};
#endif // MAINWINDOW_H
In MainWindow.cpp I try this
aPLayer = new Player("X");
and I get this error :
../tictactoe/mainwindow.cpp: In constructor 'MainWindow::MainWindow(QWidget*)':
../tictactoe/mainwindow.cpp:6:26: error: no matching function for call to 'Player::Player()'
ui(new Ui::MainWindow)
I tried making the QString mutable, I have also a constructor in Player.cpp that takes a QString and assign it to the Player's member.
Any indication as to what I should do next ? Can I initialize Player in the MainWindow definition directly ?