0

If inherit two abstract classes with a pure virtual method of the same name then what happens if I implement that method? Do I implement them for both abstract classes or does the compiler choose one to implement?

/ConsoleCalc::DataFlow::Main

namespace ConsoleCalc {

  namespace DataFlow
  {

    class Main
    {

      public:
        Main();
        virtual ~Main()=0; // exit
        virtual int Start() =0;

    };

  };
};

//ConsoleCalc::UserInterface::Menu
#include <iostream>

namespace ConsoleCalc {

  namespace UserInterface
  {

        class Menu
        {
          private:
            std::string MenuText;
          public:
            Menu();
            virtual ~Menu()=0;
            virtual int Start() =0;
        };
  };
};

//ConsoleCalc::
#include "Main.h"
#include "Menu.h"
namespace ConsoleCalc
{
  namespace Application
  {
    class Application :
                public ConsoleCalc::DataFlow::Main,
                private ConsoleCalc::UserInterface::Menu
    {
      public:
        Application();
        virtual ~Application() =0;
        virtual int Start(); //implementation
    };
  };
};

The method is question is Start. Is there a way implement both Start methods? Or does one implementation suffice for both? Or does the compiler somehow choose which one gets implemented, possibly throwing out the other?

  • Given the answers in [this other question](http://stackoverflow.com/questions/14754393/how-to-implement-virtual-functions-with-the-same-name-in-multiple-inheritance) it looks like a single implementation satisfying both is valid. However different implementations require additional work. – Guvante Mar 26 '15 at 00:52
  • possible duplicate of [Inherit interfaces which share a method name](http://stackoverflow.com/questions/2004820/inherit-interfaces-which-share-a-method-name) – Dale Wilson Apr 20 '15 at 14:32

0 Answers0