title: Slicing and then polymorphism
body: <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  namespace  Q20
  {
  
  //Base Class
  
  class Base
  {
      //Add some context to remove posting errors lol
  public:
      Base(Base *b = NULL)
      {
          m_b = b;
      }
      Base *m_b;
      virtual void func()
      {
          cout &lt;&lt; endl &lt;&lt; "B";
          if(m_b)
          {
              m_b-&gt;func();
          }
          else
          {
              m_b = (Base *)1;
          }
          return;
      }
  };
  
  //Derived 1 Class
  
  class D1 : public Base
  {
      //Add some context to remove posting errors lol
  public:
      D1(Base *b = NULL)
      {
          m_b = b;
      }
      void func(Base *b)
      {
          cout &lt;&lt; endl &lt;&lt; "D1";
          m_b-&gt;func();
      }
  };
  
  //Derived 2 Class
  
  class D2 : public Base
  {
      //Add some context to remove posting errors lol
  public:
      D2(Base *b = NULL)
      {
          m_b = b;
      }
      void func()
      {
          cout &lt;&lt; endl &lt;&lt; "D2";
          m_b-&gt;func();
      }
  };
  
  //Derived 3 Class
  
  class D3 : public Base
  {
      //Add some context to remove posting errors lol
  public:
      D3(Base *b = NULL)
      {
          m_b = b;
      }
      void func()
      {
          cout &lt;&lt; endl &lt;&lt; "D3";
          m_b-&gt;func();
      }
  };
  
  void Q20()
  {
      Base *obj = new D2(new D1(new D3(new Base)));
  
      // The above is the confusing part is there any slicing occurring above and what
      // is going to be the call sequence below...
  
      obj-&gt;func();
      cout &lt;&lt; endl;
      return;
  }
  };
  
  //Posting question is tough
  int main()
  {
      Q20::Q20();
      return 0;
  }
  </code></pre>