title: Child class calls parent member instead of its own member
body: <p>I'm trying to implement a couple of classes that share a lot of properties, by means of two classes that inherit certain members from a common parent class. In practice, what changes is how they handle a particular member, that would also be inherited, as it would be required from other members of the parent class:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  class Parent{
  public:
      Parent();
      Parent(const int _arg);
      ~Parent();
      int member1(const std::vector&lt;float&gt; _args);
      int member2(const std::vector&lt;float&gt; _args) { std::cout &lt;&lt; shared(0.0) &lt;&lt; std::endl;};
      int member3(const std::vector&lt;float&gt; _args);
      float shared(const float _val) {return 0.0;}; //dummy call in order for code to be compilable
  
  protected:
      int protected_member1;
      int protected_member2;
      int protected_member3;
  };
  
  class Child1 : public Parent {
  public:
      Child1(const int _arg):Parent(_arg);
      ~Child1();
      float shared(const float _val) {return 2.1;};
  }
  
  class Child2 : public Parent {
  public:
      Child2(const int _arg):Parent(_arg);
      ~Child2();
      float shared(const float _val) {return 1.7;};
  }
  </code></pre>
  
  <p>In practice, <code>shared(const float _val)</code> does more complex and problem-specific stuff, I tried to simplify the code in order to illustrate the issue more clearly (and removed irrelevant parts of the code as the definition of the remaining class members). However, when I call <code>member2(const std::vector&lt;float&gt; _args)</code> from each of the child classes, what is called is the base class member <code>shared(const float _val)</code> and not the child member.  </p>
  
  <pre><code>int main(int argc, char const *argv[]){
      Parent p;
      Child1 c1;
      Child2 c2;
  
      c1.member2(std::vector&lt;float&gt; (5,1.0));
      c2.member2(std::vector&lt;float&gt; (5,1.0));
  
      return 0;
  }
  </code></pre>
  
  <p>What am I doing wrong? Would a different approach to the problem make more sense?</p>