title: In C++ Is there a way for the Child to reuse the the Parent class implementation of the pure virtual function defined in GrandParent
body: <p>Consider the below code, EventGeneratorBase is a helper class intended to provide the actual implementation for <code>AddEventHandler()</code> and I would like to use that implementation in the class <code>RemoteControl</code> instead of explicity defining it. I know it's not possible to instantiate <code>RemoteControl</code> without defining the method but is there a shortcut or an easy way to avoid manually defining the methods.</p>
  
  <hr>
  
  <p><em>Note: The code in it's present form doesn't compile because RemoteControl can't be instantiated.</em></p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;memory&gt;
  
  template&lt;class TEventHandler&gt; struct IEventGenerator {
      virtual ~IEventGenerator() = default;
      virtual void AddEventHandler(std::weak_ptr&lt;TEventHandler&gt; eventHandler) = 0;
  };
  
  template &lt;class TEvents&gt; struct EventGeneratorBase : IEventGenerator&lt;TEvents&gt; {
      void AddEventHandler(std::weak_ptr&lt;TEvents&gt; target) {
          _eventHandlers.push_back(target);
      }
  
      std::vector&lt;std::weak_ptr&lt;TEvents&gt;&gt; GetEventHandlers() {
          return _eventHandlers;
      }
  
  private:
      std::vector&lt;std::weak_ptr&lt;TEvents&gt;&gt; _eventHandlers;
  };
  
  
  struct IControlEvents {
      virtual ~IControlEvents() = default;
      virtual void PowerOn() = 0;
      virtual void PowerOff() = 0;
  };
  
  struct IRemoteControl  : IEventGenerator&lt;IControlEvents&gt; {
      virtual ~IRemoteControl() = default;
      virtual void Toggle() = 0;
  };
  
  struct RemoteControl : IRemoteControl, EventGeneratorBase&lt;IControlEvents&gt; {
      // I don't want to define AddEventHandler() in this class and
      // would like to inherit the implementation from EventGeneratorBase
  
      void Toggle() {
          for (auto tref : GetEventHandlers()) {
              auto t = tref.lock();
              if (t) {
                  t-&gt;PowerOn();
                  t-&gt;PowerOff();
              }
          }
      }
  };
  
  struct Light : IControlEvents {
      Light(std::string color) : _color(color) { }
  
      void PowerOn() {
          std::cout &lt;&lt; _color &lt;&lt; "::Light ON!" &lt;&lt; std::endl;
      }
  
      void PowerOff() {
          std::cout &lt;&lt; _color &lt;&lt; "::Light OFF!" &lt;&lt; std::endl;
      }
  
  private:
      std::string _color;
  };
  
  int main() {
      std::shared_ptr&lt;IRemoteControl&gt; remote(new RemoteControl); // ERROR: Can't instantiate
      std::shared_ptr&lt;IControlEvents&gt; light1(new Light("GREEN"));
      std::shared_ptr&lt;IControlEvents&gt; light2(new Light("RED"));
  
      remote-&gt;AddEventHandler(light1);
      remote-&gt;AddEventHandler(light2);
      remote-&gt;Toggle();
  
      return 0;
  }
  </code></pre>