interchangeable derived class method from base class c++
<p>i am pretty sure this is a simple question for a long time c++ user, this should be a pattern or the problem should be solved in any other way but given i am Python developer and a total novice with c++ i don't know how it's usually done.</p>

<p>Suppose that i have a class where i want to store a pointer to an object that can be of 1 of two different classes that respects an interface, for example:</p>

<pre><code>class AllPlayers
{
  public:
  virtual void play();
};

class VlcPlayer: public AllPlayers
{
  public:
  virtual void play();
};

class Mplayer: public AllPlayers
{
  public:
  virtual void play();
};

class MyMediaPlayer
{
  public:
  MyMediaPLayer(int playerType);
  AllPlayers m_player;
};

MyMediaPlayer::MyMediaPlayer(int PlayerType)
{
  if (PlayerType == 0) {
    VlcPlayer tmp_player;
    m_player = static_cast&lt;AllPlayers&gt; (tmp_player);
  }
  else {
    Mplayer tmp_player;
    m_player = static_cast&lt;AllPlayers&gt; (tmp_player);
  }
}

MyMediaPlayer test(0);
test.play();
</code></pre>

<p>First, i know this would not work and that it seems pretty normal why but how could i get this effect? i would like to have a member of a class for what i am going to use ever the same methods, implemented using a interface and i would like to avoid trying to cast to every of the derived classes every time i am going to use one of his methods.</p>
