2012-02-26 111 views
0

我遇到以下代碼有問題,我不明白爲什麼編譯器不能識別不同的類型,即使我在聲明之前定義了它們核心類。 另外我沒有看到無限循環的可能性。錯誤:ISO C++禁止聲明'對象'沒有類型

下面的代碼:

#ifndef CORE_H 
#define CORE_H 
#define STAGING 

//core 
class SqlSaver; 
class Indexer; 
#include <QLayout> 
#include <QMainWindow> 
#include <QSplitter> 
#include <QStatusBar> 
#include <QSystemTrayIcon> 

//macros 
#include "preprocess.h" 

//Interfaces 


class PlayListInterface; 
class SearchLineInterface; 
class MetaDataInterface; 
class DriveInterface; 
class PlayingInterface; 
class ProgressInterface; 
class Updater; 
class DailySongInterface; 
class SystemTrayIcon; 
class Playbox; 
class EditInterface; 

class Core : public QObject 
{ 
    Q_OBJECT 

public: 

    Core(QMainWindow*); 

    QWidget *initInterfaces(); 

    MetaDataInterface *metadatainterface(); 
    //DriveInterface *driveinterface(); 
    PlayListInterface *playlistinterface(); 
    SearchLineInterface *searchlineinterface(); 
    PlayingInterface *playinginterface(); 
    ProgressInterface *progressinterface(); 
    Playbox *playbox(); 
    SystemTrayIcon *systemtrayicon(); 
    Updater *updater(); 
    SqlSaver* getSqlControl(); 
    EditInterface* editinterface(); 
    void place(float coef); 
    void afterLaunch(); 
    QString getFileContent(const QString& path); 

    void setStatus(const QString&); 
    QStatusBar* bar(); 
    void scanFolders(); 
    QMainWindow* getParent(); 
    QStringList dictionnary(); 
    InterfaceName interface() const; 

public slots: 
    void swapInterface(InterfaceName); 


private: 

    QWidget *m_central; 
    QMainWindow *m_parent; 
    QStatusBar* m_bar; 
    QStringList m_dictionnary; 
    SystemTrayIcon *m_tray; 

    SqlSaver *sqlControl; 

    PlayListInterface *m_playlistinterface; 
    SearchLineInterface *m_searchlineinterface; 
    //DriveInterface *m_driveinterface; 
    MetaDataInterface *m_metadatainterface; 
    PlayingInterface *m_playinginterface; 
    ProgressInterface *m_progressinterface; 
// Updater *m_updater; 
    BoutonRevenir *m_boutonrevenir; 
    Playbox *m_playbox; 
    EditInterface *m_editinterface; 
    InterfaceName m_interface; 

}; 
#endif 

還有的編譯器輸出:

make: Entering directory `/Users/adriencanterot/Projects/compilation' 
g++ <...> ../src/mainwindow.cpp 
In file included from ../src/mainwindow.cpp:5: 
../src/core.h:43: error: ISO C++ forbids declaration of 'MetaDataInterface' with no type 
../src/core.h:43: error: expected ';' before '*' token 
../src/core.h:47: error: ISO C++ forbids declaration of 'PlayingInterface' with no type 
../src/core.h:47: error: expected ';' before '*' token 
../src/core.h:48: error: ISO C++ forbids declaration of 'ProgressInterface' with no type 
../src/core.h:48: error: expected ';' before '*' token 
../src/core.h:49: error: ISO C++ forbids declaration of 'Playbox' with no type 
../src/core.h:49: error: expected ';' before '*' token 
../src/core.h:82: error: ISO C++ forbids declaration of 'MetaDataInterface' with no type 
../src/core.h:82: error: expected ';' before '*' token 
../src/core.h:83: error: ISO C++ forbids declaration of 'PlayingInterface' with no type 
../src/core.h:83: error: expected ';' before '*' token 
../src/core.h:84: error: ISO C++ forbids declaration of 'ProgressInterface' with no type 
../src/core.h:84: error: expected ';' before '*' token 
../src/core.h:86: error: ISO C++ forbids declaration of 'BoutonRevenir' with no type 
../src/core.h:86: error: expected ';' before '*' token 
../src/core.h:87: error: ISO C++ forbids declaration of 'Playbox' with no type 
../src/core.h:87: error: expected ';' before '*' token 
../src/mainwindow.cpp: In constructor 'MainWindow::MainWindow(QWidget*)': 
../src/mainwindow.cpp:25: error: 'class Core' has no member named 'metadatainterface' 
make: *** [obj/mainwindow.o] Error 1 
make: Leaving directory `/Users/adriencanterot/Projects/compilation' 

和這裏的preprocess.h:

#ifndef PREPROCESS_H 
#define PREPROCESS_H 
#include <QDebug> 
#include <QFile> 

#define REQUETE(q) QSqlQuery requete; if(!requete.exec(q)) { qDebug() << requete.lastError() << " | Q = " << requete.lastQuery(); } 
#define QUERY(q) if(!query.exec(q)) { qDebug() << query.lastError() << " | \n\nQ = " << query.lastQuery() << "\n\n"; } 
#define NB_CHAMPS_DATABASE 14 
#ifdef Q_WS_WIN 
#define FORMATS_SUPPORTES "*.mp3" << "*.wma" << "*.ogg"; 
#else 
#define FORMATS_SUPPORTES "*.mp3" << "*.m4a" << "*.wma" << "*.ogg"; 
#endif 
#define D(bug) qDebug() << bug; 
#define WIDTH_LEFT 200 
#define CHAR_NUM_LIST 50 
#define RUNNING_WORDS QString("the "); 
#define MAX_ELEMENT_SHOWN 500 
#ifdef Q_OS_WIN 
#define FMOD 
#else 
#define VLC 
#endif 

enum ContentType { 

    Dir, Playlist, Entire, Playbox, Empty 
}; 

enum ContentTypeForLabel { 

    Label, LineEdit, clickableLabel 
}; 

enum InterfaceName { 

    PlayingInterface, MetaDataInterface, ProgressInterface 
}; 

enum Action { 

    Repeat, Random, Normal 
}; 

enum progressionStyle { 
    progression, searching 
}; 

enum insertError { 
    AlreadyExists, CantDecodeTag, SqlError, NoError 
}; 

struct ProgressionInfo { 
    int progression; 
    int maximum; 
    QString phrase; 
    progressionStyle style; 
}; 
enum searchResultType { 
    Song = 0, Artist =1, Album = 2, Nothing = 3 
}; 
enum State{ 
    Playing, Paused, Stopped 
}; 

enum Provenance { 
    fromPlaybox, fromPlaylist, fromWeb, fromNowhere 
}; 


#endif // PREPROCESS_H 
+0

你有沒有運行過'moc'您的文件? – spencercw 2012-02-26 10:28:41

+1

你的''preprocess.h「'中有什麼? – Lol4t0 2012-02-26 10:51:03

+0

我將postprocess.h的內容添加到了帖子 – acanterot 2012-02-26 13:39:58

回答

3

您同時使用了enum價值觀和相同的標識符class名稱。他們發生衝突。

例如,

enum InterfaceName { 
    PlayingInterface, MetaDataInterface, ProgressInterface 
}; 

class MetaDataInterface; 

這裏enumMetaDataInterface衝突與class MetaDataInterface

如果你想保存的命名,但prvent衝突,你可以換用相同的名字命名每一個枚舉,例如:

namespace InterfaceName { 
enum InterfaceName { 
    PlayingInterface, MetaDataInterface, ProgressInterface 
}; 
}; 

class MetaDataInterface; 

現在,您可以參考class

MetaDataInterface* i = getInterfaceFromSomeWhere(); 

和到enum就像

InterfaceName::InterfaceName name = InterfaceName::MetaDataInterface; 

或者,如果你可以使用c++11,您可以使用class enum

enum class InterfaceName { 
    PlayingInterface, MetaDataInterface, ProgressInterface 
}; 

class MetaDataInterface; 

//.... 

MetaDataInterface* i = getInterfaceFromSomeWhere(); 
InterfaceName name = InterfaceName::MetaDataInterface; //note syntax difference here! 
+0

或者使用C++ 11'class enum'! – rubenvb 2012-02-26 17:04:59

+0

@rubenvb,謝謝,我添加到帖子 – Lol4t0 2012-02-26 17:18:46

+0

感謝它幫助了很多! – acanterot 2012-02-27 09:19:44

相關問題