你能帮我理解我做错了什么。 我有NetBeans,MinGW编译器和Qt库。
*的 Figure.h *
class Figure: public QObject{ //18
Q_OBJECT
public:
Figure(); //32
};
Figure.cpp
Figure:: Figure(){ // 16
}
错误消息是:
Figure.h:18:7: error: candidates are: Figure::Figure(const Figure&)
Figure.h:32:17: error: Figure::Figure()
Figure.cpp:16:1: error: prototype for 'Figure::Figure()' does not match any in class 'Figure'
顺便说一下,我试图遵循这个Figure(const Figure&)
模式。它不起作用。
稍后添加(按照要求提供更多代码):
Figure.h
#ifndef FIGURE_H
#define FIGURE_H
#include <QtGui/QApplication>
#include <QFrame>
#include <initializer_list>
#pragma once
enum colours {RED, GREEN, BLUE, YELLOW, MAGENTA};
class Figure: public QObject{
Q_OBJECT
public:
int shape[4][4];
private:
int previous_shape;
int current_shape;
int current_x;
int current_y;
int previous_x;
int previous_y;
colours colour;
public:
Figure();
int testint;
int test[2];
void change_figure();
void roll_back();
void set_coordinates(int direction);
void set_colour();
void rotate();
int get_x();
int get_y();
int* get_shape();
// signals:
// void transmitInfo();
};
Figure.cpp
#include "Figure.h"
#include <cstdlib>
#include <QtGui>
#include <QtGui/QApplication>
#include <iostream>
#include <initializer_list>
template <class T>
Figure:: Figure(){
//shape = {{1, 1}, {1, 1}};
previous_shape = 1;
current_shape = 1;
current_x = 5;
current_y = 5;
previous_x = 5;
previous_y =5;
colour = RED;
}
答案 0 :(得分:4)
在template <class T>
定义之前.cpp
文件中Figure::Figure()
执行此操作的内容是什么?您的Figure
类未在.h
文件中声明为模板。