C++ 未知类型名称错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13186426/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unknown type name error
提问by Vincenzo Pii
I'm sure it's something obvious but I just can't see it: xcode is suddenly giving me all sorts of errors when I try to use my Note
class (which is used very frequently).
我确定这是显而易见的,但我只是看不到它:当我尝试使用我的Note
类(使用非常频繁)时,xcode 突然给了我各种各样的错误。
Here's what the class header looks like:
这是类标题的样子:
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();
};
EDIT
编辑
Here's the full compiler error message:
这是完整的编译器错误消息:
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 ¬e){
^
/Users/osxursnm/Development/SynthSequencer2/SynthSequencer2/Pattern.h:24:23: error: expected ')'
void addNote(Note const ¬e){
^
/Users/osxursnm/Development/SynthSequencer2/SynthSequencer2/Pattern.h:24:17: note: to match this '('
void addNote(Note const ¬e){
^
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 ¬e);
^
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 ¬e);
^
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 ¬e);
^
/Users/osxursnm/Development/SynthSequencer2/SynthSequencer2/Track.h:33:34: error: unknown type name 'Note'
Note &addNoteAndReturnReference(Note ¬e);
^
/Users/osxursnm/Development/SynthSequencer2/SynthSequencer2/Track.h:34:18: error: unknown type name 'Note'
void removeNote(Note ¬e);
^
14 errors generated.
回答by Vincenzo Pii
My guess is that you have a cross-referencing problem.
我的猜测是你有一个交叉引用问题。
In Note.h
you include Track.h
which uses an object of type Note
. Use a forward declaration for Note
in the Track.h
file and include the Note.h
file only in Track.cpp
.
在Note.h
你包括Track.h
它使用类型的对象Note
。Note
在Track.h
文件中使用前向声明,并Note.h
仅将文件包含在Track.cpp
.
So try with
所以尝试
class Note;
before the declaration of class Track
in the Track.h
file and remove the #include "Note.h"
statement at the beginning of the file.
类的声明之前,Track
中Track.h
文件并删除#include "Note.h"
语句在文件的开头。