I have a struct declared as follows:
#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;
};
and struct Song declared in another file:
#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;
};
I have both struct definitions in headers, and both are #included as they should be.
When I compile I get an error at
std:vector<Song> songs;
error ‘Song’ was not declared in this scope
What am I missing?
playlist.h includes song.h
song.h should NOT include playlist.h
Header guards prevent infinite recursion, they don’t fix circular dependencies.
Currently song.h does include playlist.h. Then when playlist.h includes song.h, nothing happens (because of the header guard), and
Songis not defined. So playlist.h produces errors.