0

你能帮我理解我做错了什么吗?我包含 NetBeans、MinGW 编译器和 Qt 库。

*图.h *

class Figure: public QObject{ //18
    Q_OBJECT
        public:
                Figure(); //32               
};

图.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&)模式。它没有用。

稍后添加(按要求添加更多代码):

图.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();            
};

图.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;   
}
4

1 回答 1

4

在定义之前在你的文件中template <class T>做了什么?您的类未在文件中声明为模板。.cppFigure::Figure()Figure.h

于 2013-05-09T19:20:34.863 回答