2013-05-09 49 views
0

您能否幫我理解我在做什麼錯誤。 我有NetBeans,MinGW編譯器和Qt庫。'Figure :: Figure()'的原型不匹配'圖'

* 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

Q_OBJECT是如何定義的? – 2013-05-09 19:11:16

+0

你可以更新你的文章幷包含整個Figure.h和Figure.cpp嗎? – kenrogers 2013-05-09 19:14:26

+0

@Scott Jones,Q_OBJECT是一個Qt宏。 – Trts 2013-05-09 19:20:37

回答

4

是什麼template <class T>在那裏做什麼你.cpp file Figure::Figure() defini重刑?您的Figure類未在.h文件中聲明爲模板。

+0

也不可能,'QObject'派生類不能支持類模板,因爲'moc'。 – cmannett85 2013-05-09 19:23:19