2012-11-01 185 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 ',它现在还不知道!在这种情况下使用警卫无助。不幸的是,当这种循环依赖问题发生很长时间时,这就是您的设计应该重新审视的标志。 –