【发布时间】:2011-11-04 20:45:49
【问题描述】:
我有一个声明如下的结构:
#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;
};
和在另一个文件中声明的 struct Song:
#ifndef SONG_H
#define SONG_H
#include "playlist.h"
#include "time.h"
struct Song {
std::string title;
std::string artist;
std::string album;
int track;
Time length;
};
我在标头中有两个结构定义,并且它们都被#included 了。
编译时出现错误
std:vector<Song> songs;
错误“歌曲”未在此范围内声明
我错过了什么?
【问题讨论】:
-
你确定在文件中包含了
Song的定义文件,定义了Playlist?并且它在同一个命名空间中? -
你是如何“将他们包括在内”的? (提示:你不是;))
-
请向我们展示您使用定义的文件。
标签: c++ data-structures vector struct initialization