2012-11-01 197 views
3

我確定這是顯而易見的東西,但我看不到它:當我嘗試使用我的Note類(這非常頻繁地使用)時,xcode突然給我提供各種錯誤。未知類型名稱錯誤

這裏的類頭的樣子:

class Note : public Playable{ 

private: 

public: 

    double theta; 
    double frequency; 
    int duration; 
    int startTime; // tussen 1 en 32 
    int measureNumber; 
    float velocity; 
    Playable *track; 
    virtual float getValue(); 

    static double calculateNoteFrequency(int aOctaveNumber, note_name aNoteName); 

    Note(double aFreq, float aVelocity, int aDuration, int aMeasureNumber, int aStarttimeInsideMeasure, Playable *aTrack){ 
//  theta = 0; 
     Note(); 
     frequency = aFreq; 
     duration = aDuration; 
     velocity = aVelocity; 
     measureNumber = aMeasureNumber; 
     startTime = aStarttimeInsideMeasure; 
     track = aTrack; 
    } 

    Note(){ 
     theta = 0; 
    } 
    void toString(); 

}; 

編輯

下面是完整的編譯器錯誤消息:

In file included from /Users/osxursnm/Development/SynthSequencer2/SynthSequencer2/Note.cpp:9: 
In file included from /Users/osxursnm/Development/SynthSequencer2/SynthSequencer2/Note.h:14: 
In file included from /Users/osxursnm/Development/SynthSequencer2/SynthSequencer2/Track.h:16: 
/Users/osxursnm/Development/SynthSequencer2/SynthSequencer2/Pattern.h:19:12: error: use of undeclared identifier 'Note' 
    vector<Note> notelist; 
     ^
/Users/osxursnm/Development/SynthSequencer2/SynthSequencer2/Pattern.h:19:18: error: C++ requires a type specifier for all declarations 
    vector<Note> notelist; 
       ^~~~~~~~ 
/Users/osxursnm/Development/SynthSequencer2/SynthSequencer2/Pattern.h:23:12: error: use of undeclared identifier 'Note' 
    vector<Note> getNotelist(); 
     ^
/Users/osxursnm/Development/SynthSequencer2/SynthSequencer2/Pattern.h:23:18: error: C++ requires a type specifier for all declarations 
    vector<Note> getNotelist(); 
       ^~~~~~~~~~~ 
/Users/osxursnm/Development/SynthSequencer2/SynthSequencer2/Pattern.h:24:18: error: unknown type name 'Note' 
    void addNote(Note const &note){ 
       ^
/Users/osxursnm/Development/SynthSequencer2/SynthSequencer2/Pattern.h:24:23: error: expected ')' 
    void addNote(Note const &note){ 
        ^
/Users/osxursnm/Development/SynthSequencer2/SynthSequencer2/Pattern.h:24:17: note: to match this '(' 
    void addNote(Note const &note){ 
       ^
In file included from /Users/osxursnm/Development/SynthSequencer2/SynthSequencer2/Note.cpp:9: 
In file included from /Users/osxursnm/Development/SynthSequencer2/SynthSequencer2/Note.h:14: 
In file included from /Users/osxursnm/Development/SynthSequencer2/SynthSequencer2/Track.h:17: 
In file included from /Users/osxursnm/Development/SynthSequencer2/SynthSequencer2/Synth.h:11: 
/Users/osxursnm/Development/SynthSequencer2/SynthSequencer2/Oscillator.h:21:18: error: unknown type name 'Note' 
    void setNote(Note &aNote); 
       ^
/Users/osxursnm/Development/SynthSequencer2/SynthSequencer2/Oscillator.h:23:20: error: unknown type name 'Note' 
    float getValue(Note &note); 
       ^
In file included from /Users/osxursnm/Development/SynthSequencer2/SynthSequencer2/Note.cpp:9: 
In file included from /Users/osxursnm/Development/SynthSequencer2/SynthSequencer2/Note.h:14: 
In file included from /Users/osxursnm/Development/SynthSequencer2/SynthSequencer2/Track.h:17: 
/Users/osxursnm/Development/SynthSequencer2/SynthSequencer2/Synth.h:47:21: error: unknown type name 'Note' 
    float getSample(Note &note); 
        ^
In file included from /Users/osxursnm/Development/SynthSequencer2/SynthSequencer2/Note.cpp:9: 
In file included from /Users/osxursnm/Development/SynthSequencer2/SynthSequencer2/Note.h:14: 
/Users/osxursnm/Development/SynthSequencer2/SynthSequencer2/Track.h:30:17: error: use of undeclared identifier 'Note' 
     multimap<long, Note> noteList; 
        ^
/Users/osxursnm/Development/SynthSequencer2/SynthSequencer2/Track.h:30:23: error: C++ requires a type specifier for all declarations 
     multimap<long, Note> noteList; 
          ^~~~~~~~ 
/Users/osxursnm/Development/SynthSequencer2/SynthSequencer2/Track.h:33:2: error: unknown type name 'Note' 
     Note &addNoteAndReturnReference(Note &note); 
     ^
/Users/osxursnm/Development/SynthSequencer2/SynthSequencer2/Track.h:33:34: error: unknown type name 'Note' 
     Note &addNoteAndReturnReference(Note &note); 
             ^
/Users/osxursnm/Development/SynthSequencer2/SynthSequencer2/Track.h:34:18: error: unknown type name 'Note' 
     void removeNote(Note &note); 
         ^
14 errors generated. 
+0

你應該添加你的編譯器錯誤消息(整個消息)和真實代碼,所以我們可以幫你 – alestanis

+0

我發佈了編譯器消息代碼 – networkprofile

+0

我猜你在Note.h文件中有錯誤。檢查你沒有忘記分號,也許是在你的課程結束? – alestanis

回答

13

我的猜測是,你有一個交叉引用問題。

Note.h中包含Track.h,它使用Note類型的對象。在Track.h文件中使用Note的正向聲明,並僅在Track.cpp中包含Note.h文件。

因此,與

class Note; 

嘗試Track類在Track.h文件中的聲明之前,並在文件的開頭刪除#include "Note.h"聲明。

+0

這也將是我的猜測... – Roddy

+0

這似乎解決了Track類的問題,但它看起來像我需要爲多個類做這個。任何想法可能導致這一點?我爲每一個類使用'#ifndef',這直到一小時前纔開始。謝謝你的幫助! – networkprofile

+1

@Sled你的頭文件之間有循環依賴關係:當編譯器處理'Note.h'時,它發現包含了'Track.h',然後它開始處理'Track.h',並找到一個類型爲'Note ',它現在還不知道!在這種情況下使用警衛無助。不幸的是,當這種循環依賴問題發生很長時間時,這就是您的設計應該重新審視的標誌。 –