title: Is there a way to call a method which will get defined in inherited class?
body: <p>I've made this fragment of code:</p>
  <pre><code>template &lt;typename T&gt;
  class Vector : public vector&lt;T&gt; {
      static constexpr auto identity   = [](T x) {return x;};
      static constexpr auto accept_all = [](T x) {return true;};
      static constexpr auto sum        = [](T x, T y) {return x+y;};
  public:
      Vector&lt;T&gt;&amp; map(T (*f)(T x) = identity) {
          for(int i=0; i &lt; this-&gt;size(); i++)
              (*this)[i] = f((*this)[i]);
  
          return *this;
      }
      Vector&lt;T&gt;&amp; filter(bool (*acceptable)(T x) = accept_all) {
          for(int i=0; i &lt; this-&gt;size(); i++)
              if(not acceptable((*this)[i]))
                  this-&gt;erase(this-&gt;begin() + i);
  
          return *this;
      }
      T fold(T (*f)(T x, T y) = sum) {
          T result = (*this)[0];
          for(int i=1; i &lt; this-&gt;size(); i++)
              result = f(result, (*this)[i]);
  
          return result;
      }
  };
  </code></pre>
  <p>It extends the <code>vector</code> class with functional methods <code>map</code>, <code>filter</code>, <code>fold</code>. Notice how <code>vector</code> can be replaced with a <code>deque</code> and it's still going to work because these classes share a common interface. In fact, anything that implements the <code>operator[]</code>, <code>size()</code> and <code>erase()</code> methods could be used instead. I'd like to generalize this with inheritance.</p>
  <p>Let's say there exists such a class <code>FunctionalMethods</code> that can be inherited from by any class which supports the <code>operator[]</code>, <code>size()</code>, <code>erase()</code> methods, and which will implement the previously mentioned functionality.</p>
  <p>If such a class existed, writing</p>
  <pre><code>template &lt;typename T&gt;
  class Vector : public vector&lt;T&gt;, public FunctionalMethods {};
  </code></pre>
  <p>Exactly as is would create exactly the same class as in the first example.</p>
  <p><strong>For such a class to exist, there needs to be a way to call methods which will get defined in another inherited class. Can it somehow be done?</strong></p>
  <p>I know that I can generalize this example by using templates:</p>
  <pre><code>template &lt;template&lt;class&gt; class Container, class T&gt;
  class Functional : public Container&lt;T&gt; {
      ...
  };
  </code></pre>
  <p>where the <code>Functional</code> class has exactly the same implementation as the previous <code>Vector</code> class, but every occurrence of <code>Vector&lt;T&gt;</code> is replaced with <code>Container&lt;T&gt;</code>. However, this method yields an ugly syntax (for example, <code>Functional&lt;vector, int&gt;</code> has to be used instead of <code>Vector&lt;int&gt;</code>). It's also less general than the previously mentioned inheritance method because it does not allow splitting a class into individual modules, which can be reused.</p>