title: Polymorphic pointer change at run time
body: <p>I am really confused about polymorphic pointers. I have 2 classes derived from an interface as shown below code.</p>
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  class Base  {
  
  public:
      virtual ~Base() { }
      virtual void addTest() = 0;
  };
  
  class B: public Base {
  
  public:
      B(){}
      ~B(){}
  
      void addTest(){
          cout &lt;&lt; &quot;Add test B\n&quot;;
      }
  };
  class C: public Base {
  
  public:
      C(){}
     ~C(){}
  
      void addTest(){
          cout &lt;&lt; &quot;Add test C\n&quot;;
      }
  private:   
      void deleteTest(){
          
      }
      
  };
  
  int main()
  {
      Base *base = new B();
      base-&gt;addTest();
      base = new C();
      base-&gt;addTest();
      return 0;
  }
  
  </code></pre>
  <p>I want to change the pointer dynamically according to a condition at run time to use the same pointer with different kinds of scenarios.</p>
  <p>Derived classes are different from each other, so what happens in memory when the polymorphic pointer object changes?</p>
  <p>If that usage is not good practice, how can I change the polymorphic pointer object dynamically at the run time?</p>