2011-11-04 65 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.