title: Calling derived class function from base class function
body: <p>In the following code, in the function <code>set(int, int)</code> of class <code>Base</code>, I want to call the derived class function <code>showK()</code>. Is there a way to do this?</p>
  
  <p>I can not declare <code>showK()</code> function in class <code>Base</code> and i can not make that as virtual. This is a restriction for me.</p>
  
  <pre><code>class Base{
      int i, j;
      public:
      void set( int, int );
      void show() { cout &lt;&lt; i &lt;&lt; " " &lt;&lt; j &lt;&lt; "\n"; }
  };
  
  void Base:: set(int a, int b)
  { 
      i=a; j=b; 
      //Here I want to call the function showk() of class derived . Is there a way to call?.
  }
  
  class derived : public base {
      int k;
      public:
      derived(int x) { k=x; }
      virtual void showk() { cout &lt;&lt; k &lt;&lt; "\n"; }
  };
  
  int main()
  {
      derived ob(3);
      ob.set(1, 2); // access member of base
      ob.show(); // access member of base
      ob.showk(); // uses member of derived class
      return 0;
  }
  </code></pre>
  
  <p>Thanks in advance.</p>