我想我已经激怒了“Header Guard”的神灵,但我看不到哪里。我的课程布局如下: (注意:这只是这些文件的相关信息)
主文件:
#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;
在我的主文件中。
谢谢!
答案 0 :(得分:4)
检查您的大写字母。
Playlist
和PlayList
正在使用中。
答案 1 :(得分:2)
你的大写错误...它被声明为播放列表,用作播放列表
答案 2 :(得分:1)
clang的拼写检查有助于此类事情。
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.