If you want variables to be visible within functions without having to pass them then they must be global.
You could use a global array of TsuPods to accomplish this. Many will recommend against this approach though and state that global variables are "evil".
When that global variable is the single thing that the whole program is about though, it makes sense.
#include<iostream>
//#include <iomanip>
#include <string>
//#include<ctime>// for seeding random #'s
usingnamespace std;
struct TsuPod
{
string title;
string artist;
int size;
// a function for convenient initialization of each instance
void INIT(const std::string& Title, const std::string& Artist, constint& Size)
{
title = Title;
artist = Artist;
size = Size;
}
};
constint NUM_SONGS = 3;// # of songs in the list
TsuPod songlist[NUM_SONGS];// global array - no need for initTsuPod() now
void displaySize()
{
for(int i = 0;i < NUM_SONGS;i++)
cout << songlist[i].size << endl;
}
int main(void)
{
// initialize each element of array
songlist[0].INIT("title 1", "artist 1", 3500);
songlist[1].INIT("title 2", "artist 2", 4000);
songlist[2].INIT("title 3", "artist 3", 4500);
// display function
displaySize();
cout << endl;
return 0;
}