title: Mistake when overriding C++ virtual function
body: <p>This is my situation:</p>
  
  <pre><code>class Filter3by3 {
  public:
     virtual inline Mat convolution((Mat &amp; mat, int i, int j, int rows, int cols) { 
   code
  
     }
  };
  
  class MySobel: public Filter3by3 {
  public:
    inline Vec3b convolution(Mat &amp; mat, int i, int j, int rows, int cols) {
      code
    }
  };
  </code></pre>
  
  <p>Now, when I call:</p>
  
  <pre><code>Filter3by3 f = choose_filter(filtername); // Returns a Sobel filter
  Mat mat;
  s.convolution(args);
  </code></pre>
  
  <p>The base class method is called.
  I am quite newbie at c++ method binding rules, so can you tell me where I am wrong?
  I appreciate your help.</p>
  
  <p><strong>UPDATE</strong>
  It appears that even with 
      virtual inline Mat convolution((Mat &amp; mat, int i, int j, int rows, int cols)
  It does not work.</p>
  
  <p>This is a running program, compiled with g++ -std=c++11</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  class Filter {
  public:
    Filter() { }
    virtual int ehi() {
      cout &lt;&lt; "1" &lt;&lt; endl;
      return 1;
    }
  
  };
  
  class SubFilter : public Filter {
  public:
    SubFilter() : Filter() { }
  
    int ehi() {
      cout &lt;&lt; "2" &lt;&lt; endl;
      return 2;
    }
  
  };
  
    Filter choose_filter(){
      SubFilter f;
      return f;
    }
  
    int main(int argc, char* argv[]) {
  
       Filter f = choose_filter();
       f.ehi();
       return 0;
    }
  </code></pre>
  
  <p>It prints 1 instead of 2. I used virtual to ensure dynamic binding, but it does not seem to be enough, also with "override" keyword.</p>