mcudm001
mcudm001

Reputation: 99

"Was not declared in this scope" error struct definition. c++

I'm thinking I have angered the "Header Guard" gods, but I don't see where. My program is laid out as follows: (note :this is just the relevant info on these files)

main file:

#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>

I get "Playlist was not declared in this scope" on line:

PlayList allSongs;

In my main file.

Thanks!

Upvotes: 0

Views: 5124

Answers (3)

bames53
bames53

Reputation: 88225

clang's spell checking is helpful for this type of thing.

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.

Upvotes: 1

je4d
je4d

Reputation: 7848

You've just got your capitalization wrong... it's declared as Playlist, used as PlayList

Upvotes: 2

Pubby
Pubby

Reputation: 53097

Check your capitalization.

Playlist and PlayList are being used.

Upvotes: 4

Related Questions