テトリスを作っています。さて、私のガラス (QtGlass.h) は図を作成します。ここでパラメーターを使用して、図形がどのような形状をとるべきかを指定したいと思います。
パラメータがこのエラーを引き起こす理由を教えてください:
QtGlass.h:29:23: error: expected identifier before 'L'
QtGlass.h:29:23: error: expected ',' or '...' before 'L'
このエラーが発生する場所を以下のコメントに示しました。ちなみに、パラメータなしのバリアントを示す行のコメントを外すと、機能します。
**Figure.h**
class Figure : public QObject {
Q_OBJECT
...
public:
Figure(char Shape);
//Figure();
...
};
**Figure.cpp**
Figure::Figure(char Shape) {
//Figure::Figure() {
previous_shape = 1;
colour = RED;
...
}
**QtGlass.h**
class QtGlass : public QFrame {
Q_OBJECT
...
protected:
Figure the_figure('L'); //QtGlass.h:29:23: error: expected identifier before 'L' QtGlass.h:29:23: error: expected ',' or '...' before 'L'
//Figure the_figure;
...
};
後で編集
これを使用する場合:
class QtGlass : public QFrame {
Q_OBJECT
QtGlass() : the_figure('L') {}
I get this:
QtGlass.cpp:164:50: error: no matching function for call to 'Figure::Figure()'
QtGlass.cpp:164:50: note: candidates are:
Figure.h:38:5: note: Figure::Figure(char)
Figure.h:38:5: note: candidate expects 1 argument, 0 provided
Figure.h:20:7: note: Figure::Figure(const Figure&)
Figure.h:20:7: note: candidate expects 1 argument, 0 provided
QtGlass.cpp
QtGlass::QtGlass(QWidget *parent) : QFrame(parent) {
key_pressed = false;
coord_x = 5;
coord_y = 5;
arrow_n = 0;
highest_line = 21;
this->initialize_glass();
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(moveDownByTimer()));
timer->start(1000);
}