You're close, but you need to work on calling/implementing your constructors properly:
Code:
/* musicLib.h: developed for wav an mp3 classes tutorial
Written by Dexter Valentine
Created 8/3/05 */
#include <vector>
#include <string>
using namespace std;
class Track
{
public:
Track( string title, int duration ) : name(title),lengthOfTime(duration) { }
virtual void play( ) = 0;
protected:
int lengthOfTime;
string name;
};
class Mp3 : public Track
{
public:
Mp3( string title,int duration ) : Track(title,duration) {}
void play( );
};
class Wav: public Track
{
public:
Wav( string title, int duration) : Track(title,duration) {}
void play( );
};
class Playlist
{
public:
Playlist( );
void add( Track* t ) { gimmeTrack.push_back( t ); }
void play( );
private:
typedef std :: vector< Track* > ThemTracks;
ThemTracks gimmeTrack;
};
--------------------------------------------------------------------------
/* musicImp.cc: developed for wav an mp3 classes tutorial
Written by Dexter Valentine
Created 8/3/05 */
#include <iostream>
#include <string>
#include "musicLib.h"
using namespace std;
void Mp3 :: play( )
{
cout << "Playing mp3 track: " << name << "(" << lengthOfTime << ")" << endl;
}
void Wav :: play( )
{
cout << "Playing wav track: " << name << "(" << lengthOfTime << ")" << endl;
}
Playlist :: Playlist( ) { }
void Playlist :: play( )
{
vector< Track* > :: iterator i;
for ( i = gimmeTrack.begin( ); i != gimmeTrack.end( ); ++i )
{
( *i ) ->play( );
}
}
-------------------------------------------------------------------------------
/* music.cc: developed for wav an mp3 classes tutorial
Written by Dexter Valentine
Created 8/3/05 */
#include <iostream>
#include <string>
#include <vector>
#include "musicLib.h"
using namespace std;
int main( )
{
Playlist list;
list.add( new Mp3( "Who let the dogs out?", 193 ) );
list.add( new Wav( "Meowth song", 253 ) );
list.add( new Mp3( "Thunderball", 480 ) );
list.play();
return 0;
}