Hi
I'm trying to make a version of minesweeper in Qt4. In order to do this i have subclassed QPushButton to make a new class, MinesveiperButton. This seems to work fine, however when i try to make a new grid, using a 2-dimentional array and fill it with MinesveiperButtons i get this error:
C:/C++ Qt/Minesveiper/v3/minesveiper.cpp:52: error: no match for 'operator=' in '*((*(((Minesveiper*)this)->Minesveiper::mask + ((unsigned int)(((unsigned int)i) * 4u)))) + ((unsigned int)(((unsigned int)j) * 28u))) = (operator new(28u), (<statement>, ((MinesveiperButton*)<anonymous>)))'
This is Minesveiper.h:
#ifndef MINESVEIPER_H
#define MINESVEIPER_H
#include <QMainWindow>
#include <QGridLayout>
#include "MinesveiperButton.h"
namespace Ui {
class Minesveiper;
}
Q_OBJECT
public:
~Minesveiper();
void makeBoard();
void startSpill(int h, int w, int m);
public slots:
void startEnkeltSpill();
protected:
private:
Ui::Minesveiper *ui;
int mHeight;
int mWidth;
int mines;
int antOpen;
int **board;
MinesveiperButton **mask;
};
#endif // MINESVEIPER_H
#ifndef MINESVEIPER_H
#define MINESVEIPER_H
#include <QMainWindow>
#include <QGridLayout>
#include "MinesveiperButton.h"
namespace Ui {
class Minesveiper;
}
class Minesveiper : public QMainWindow {
Q_OBJECT
public:
Minesveiper(QWidget *parent = 0);
~Minesveiper();
void makeBoard();
void startSpill(int h, int w, int m);
public slots:
void startEnkeltSpill();
protected:
void changeEvent(QEvent *e);
private:
Ui::Minesveiper *ui;
int mHeight;
int mWidth;
int mines;
int antOpen;
int **board;
MinesveiperButton **mask;
QGridLayout grid;
};
#endif // MINESVEIPER_H
To copy to clipboard, switch view to plain text mode
and this is MinesveiperButton.h:
#ifndef MINESVEIPERBUTTON_H
#define MINESVEIPERBUTTON_H
#include <QtGui/qpushbutton.h>
#include "minesveiper.h"
Q_OBJECT
public:
MinesveiperButton(int x, int y);
MinesveiperButton();
~MinesveiperButton();
void open();
void flag();
void setIcon();
//MinesveiperButton & operator=(const MinesveiperButton &rhs);
private:
int xpos;
int ypos;
};
#endif // MINESVEIPERBUTTON_H
#ifndef MINESVEIPERBUTTON_H
#define MINESVEIPERBUTTON_H
#include <QtGui/qpushbutton.h>
#include "minesveiper.h"
class MinesveiperButton : public QPushButton {
Q_OBJECT
public:
MinesveiperButton(int x, int y);
MinesveiperButton();
~MinesveiperButton();
void open();
void flag();
void setIcon();
//MinesveiperButton & operator=(const MinesveiperButton &rhs);
private:
int xpos;
int ypos;
};
#endif // MINESVEIPERBUTTON_H
To copy to clipboard, switch view to plain text mode
and finally implementation of Minesveiper::makeBoard() from Minesveiper.cpp, which is where i get the error:
void Minesveiper::makeBoard() {
/*
Deletes board and mask, and makes new arrays.
Empties grid and adds new MinesveiperButtons to grid.
*/
delete [] board;
delete [] mask;
// Empty grid
int ant = grid.count();
for(int i = 0; i < ant; i++) {
delete grid.itemAt(i);
}
// Make new arrays
board = new int *[mHeight];
mask = new MinesveiperButton *[mHeight];
for(int i = 0; i < mHeight; i++) {
board[i] = new int[mWidth];
mask[i] = new MinesveiperButton[mWidth];
for(int j = 0; j < mWidth; j++) {
board[i][j] = 0;
mask[i][j] = new MinesveiperButton(j, i);
grid.addWidget(&mask[i][j], i, j);
}
}
}
void Minesveiper::makeBoard() {
/*
Deletes board and mask, and makes new arrays.
Empties grid and adds new MinesveiperButtons to grid.
*/
delete [] board;
delete [] mask;
// Empty grid
int ant = grid.count();
for(int i = 0; i < ant; i++) {
delete grid.itemAt(i);
}
// Make new arrays
board = new int *[mHeight];
mask = new MinesveiperButton *[mHeight];
for(int i = 0; i < mHeight; i++) {
board[i] = new int[mWidth];
mask[i] = new MinesveiperButton[mWidth];
for(int j = 0; j < mWidth; j++) {
board[i][j] = 0;
mask[i][j] = new MinesveiperButton(j, i);
grid.addWidget(&mask[i][j], i, j);
}
}
}
To copy to clipboard, switch view to plain text mode
line 52 is numbered 23 here..
Can someone help me with this? I thought =operator didn't need overloading. Does it?
Just tell me if you want to view more of the code..
Bookmarks