How to overwrite a virtual method defined in a class in another class which is inside a function in C++
<p>I have a <code>class A</code> which is in a separate file(<code>sayfile1.cpp</code>)</p>

<pre><code>class A{
public:
      virtual int add(){
      int a=5;
      int b=4;
      int c = a+b;
      return c;
      }
};
</code></pre>

<p>Now in a different file(say <code>file2.cpp</code>), i have a function(i have a many other things in this function) inside which i want to create a class inherited from <code>class A</code> and implement the virtual method declared in <code>class A</code>.</p>

<pre><code>void function(Mat param1, Mat param2)
{
  //Some process here..
  ..
  ..
  int c=100;
  class B:public A{
  public:
        virtual int add(){

        return c;
        }
  };

}
</code></pre>

<p>Now if i were to call the function <code>int add()</code>, i want the result of <code>c</code> to be 100 and not 9.</p>

<p>Is it possible to do something like this in C++ ??</p>

<p>Thanks in advance</p>
