The trouble with polymorphism
Hello,
Hope somebody can help. I'm trying to output the following using polymorphism:
Playing mp3 track: Who let the dogs out? (193 secs)
Playing wav track: Meowth song (253 secs)
Playing mp3 track: Thunderball (480 secs)
I'm sure I'm close, but I'm having trouble. I keep getting 3 errors, all saying:
"...no overloaded function takes 2 parameters".
Here is the code:
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 ) { }
virtual void play( ) = 0;
protected:
int lengthOfTime;
string name;
};
class Mp3 : public Track
{
public:
Mp3( );
void play( );
};
class Wav: public Track
{
public:
Wav( );
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 << ")";
}
void Wav :: play( )
{
cout << "Playing wav track: " << &name << "(" << &lengthOfTime << ")";
}
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;
}
If somebody knows where I'm going wrong I'd really appreatiate some assistance.
Cheers,
Stabbrie :D