2011-11-04 447 views
0

我在想我已經激怒了「Header Guard」神,但我不知道在哪裏。我的程序佈局如下: (注意:這僅僅是對這些文件的相關信息)「未在此範圍內聲明」錯誤結構定義。 C++

主要文件:

#include "playlist.h" 
#include "playlistitem.h" 
#include <iostream> 
#include <fstream> 
#include <vector> 

using namespace std; 


int main (int argc, char** argv) 
    //snip 
    PlayList allSongs; 
    //snip 

playist.h:

#ifndef PLAYLIST_H 
#define PLAYLIST_H 

#include <iostream> 
#include <string> 
#include <vector> 
#include "playlistitem.h" 
#include "song.h" 
#include "time.h" 

struct Playlist { 
std::vector<Song> songs; 
Time cdTotalTime; 
int totalTime; 
}; 

plalist.cpp :

#include <iostream> 
#include <string> 
#include <vector> 
#include "playlist.h" 

song.h:

#ifndef SONG_H 
#define SONG_H 

#include <iostream> 
#include <string> 
#include "time.h" 

struct Song { 
std::string title; 
std::string artist; 
std::string album; 
int track; 
Time length; 
}; 

song.cpp:

#include "song.h" 
#include "csv.h" 
#include <sstream> 
#include <vector> 

我得到上線 「播放列表並沒有在這個範圍內聲明」:

PlayList allSongs; 

在我的主要文件。

謝謝!

+2

在你的頭文件末尾是否有#ifififif關閉了#ifndef'後衛? –

+0

你爲什麼不發佈實際的錯誤信息?當您的實際代碼行使用「PlayList」時,您說錯誤消息指出「播放列表未在此範圍內聲明」。 – Marlon

回答

4

檢查您的大小寫。

PlaylistPlayList正被使用。

+0

有類似問題...確保符合名稱空間(如果適用)。 – eliteslayer

2

你拿到你的資本錯了...它宣佈爲播放列表,作爲播放列表

1

鐺的拼寫檢查是這種類型的事情有幫助。

tmp.cpp:5:1: error: unknown type name 'PlayList'; did you mean 'Playlist'? 
PlayList pl; 
^~~~~~~~ 
Playlist 
tmp.cpp:1:8: note: 'Playlist' declared here 
struct Playlist { 
    ^
1 error generated.